in reply to Re: Re: input record separator help
in thread input record separator help

Anonymous Monk,
So my earlier assumption that you wanted to throw away non sequence lines was correct. I believe you can avoid an array all together.
#!/usr/bin/perl use strict; use warnings; my $file = $ARGV[0] || 'default'; open (DNA, '<', $file) or die "Unable to open $file for reading : $!"; my %seq; while ( <DNA> ) { my $dna = <DNA>; my $pairs = "a2" x ((length $dna) / 2); $seq{$_}++ for unpack $pairs , $dna; } print "$_ : $seq{$_}\n" for keys %seq;
Cheers - L~R

Replies are listed 'Best First'.
Re: Re: Re: Re: input record separator help
by Anonymous Monk on Mar 15, 2004 at 15:00 UTC
    hi L~R, thankyou for your help, would you mind exaplaining to me exactly what the code does? e.g. the 'a2' and 'unpack' bits? many thanks
      Anonymous Monk,
      You can check out the pack/unpack tutorial for more information, but here was my logic.
      my $pairs = "a2" x ((length $dna)/2); # The x operator (perldoc perlop) repeats LHS string times the RHS $seq{$_}++ for unpack $pairs, $dna; # Break string up into a list of 2 char strings # Increment the corresponding hash value by 1
      Cheers - L~R