Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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

Prasad


Comment on Re: printing the length of string variables
Download Code
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (13)
As of 2014-09-19 16:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (143 votes), past polls