sugar has asked for the wisdom of the Perl Monks concerning the following question:
printing the length of string variables use strict; use warnings; my ($head); while(<DATA>){ my ($x, $str, $len, $s); $s = $_; if($s=~m/^>/){ chomp($s); ($head)=(split(/ /,$s))[0]; } else{ chomp($s); $len=length($s); } print "$head length=$len\n$s\n" if($s !~m/^>/); } __DATA__ >IDnumber1 length=350 AGCTG AAGTCGCT >IDnumber2 length=350 AGAACGT ACC >IDnumber3 length=350 AGC ACTTCGCTAACT Expected output: ----------------- >IDnumber1 length=13 AGCTGAAGTCGCT >IDnumber2 length=10 AGAACGTACC >IDnumber3 length=15 AGCACTTCGCTAACT
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: chopping new line while counting length
by ikegami (Patriarch) on Jan 15, 2009 at 10:00 UTC | |
|
Re: chopping new line while counting length
by johngg (Canon) on Jan 15, 2009 at 10:21 UTC | |
|
Re: chopping new line while counting length
by andye (Curate) on Jan 15, 2009 at 11:51 UTC |