
vikas.deep
User
Jun 9, 2009, 10:27 PM
Post #3 of 7
(9383 views)
|
Re: [mhadidi2002] Extract certain words from lines
[In reply to]
|
Can't Post
|
|
didi Before posting anything or in addition to posting anything you are advised to read or roam a bit As recently as 5 june, 2009 Fishmonger(Re: [mikkin] scope of File handle June5,2009)has written the following in a thread in Beginners section. I quote
6) Slurping the file into an array is rarely the best or proper approach. I most cases you want to loop over the data "line-by-line" or "record-by-record". This and other golden tips are not only for the Original Poster (OP) but any body who is interested. Why do you slurp the file contents in an array. Please check if the following code helps you
my @arr1; open (my $FH, "in.txt") or die "cannot open the file $!"; while (<$FH>) {if ($_ =~ /\>/g||$_ =~ /\#/g){next;}else { my($num1,$num2,$num3) = unpack("xA7A*"); push @arr1, $num1,","; } } print @arr1 The output is
C:\ActivePerl>perl try.pl 4639567,4639511,4612526,4612489,4612623,4612483, and the in.txt had the following
>CHA 2 #419150.000000 12345678901234567890123456789012345678901234567890 [4639567,4639674] [4825157,4825264] 7196 [4639511,4639565] [4825101,4825155] 8416 #1346.000000 [4612526,4612558] [859583,859615] 1843 [4612489,4612510] [859547,859568] 17296 #1263.000000 [4612623,4612644] [3296095,3296116] 18439 [4612483,4612515] [3296057,3296089] 4517 -For all my suggestions " I am sure someone else can do it in a better or elegant manner!"
|