Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: printing the length of string variables

by prasadbabu (Prior)
on Jan 08, 2009 at 07:25 UTC ( #734830=note: print w/replies, xml ) Need Help??

in reply to printing the length of string variables

Hi sugar,

If I understood your requirement correctly, the below coding which is slightly modified form of yours will work. But you can do the same in more simple way.

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 >IDnumber2 length=350 AGAACGT >IDnumber3 length=350 AGC output: ------- >IDnumber1 length=5 AGCTG >IDnumber2 length=7 AGAACGT >IDnumber3 length=3 AGC


Replies are listed 'Best First'.
Re^2: printing the length of string variables
by sugar (Sexton) on Jan 08, 2009 at 07:42 UTC
    Oh yea, your right. I just realized it :) Thanks for the help.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://734830]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2020-05-26 13:44 GMT
Find Nodes?
    Voting Booth?
    If programming languages were movie genres, Perl would be:

    Results (150 votes). Check out past polls.