Tiago Hori wrote:
Hey Guys,
Hello,
I am still at the same place. I am writing these little pieces of code to try to learn the language better, so any advice would be useful. I am again parsing through tab delimited files and now trying to find fish from on id (in these case families AS5 and AS9), retrieve the weights and average them. When I started I did it for one family and it worked (instead of the @families I had a scalar $family set to AS5). But really it is more useful to look at more than one family at time (I should mention that are 2 types of fish per family one ends in PS , the other doesn't). So I tried to use a foreach loop to go through the file twice, once with a the search value set to AS5 and a second time to AS9. It works for AS5, but for some reason, the foreach loop sets $test to AS9 the second time, but it doesn't go through the while loop. What am I doing wrong? here is the code: #! /usr/bin/perl use strict; use warnings; my $file = $ARGV[0]; my @family = ('AS5','AS9'); my $i; my $ii; my $test; open (my $fh, "<", $file) or die ("Can't open $file: $!"); foreach (@family){ $test = $_; my @data_weight_2N = (); my @data_weight_3N = (); while (<$fh>){ chomp; my $line = $_; my @data = split ("\t", $line); if ($data[0] !~ /[0-9]*/){
That won't work because there are zero [0-9] characters in EVERY string: $ perl -le' my @x = qw/ 0ne 234 five67 ___ /; for my $x ( @x ) { next if $x !~ /[0-9]*/; print $x; } ' 0ne 234 five67 ___ You need to test for at least one character: if ($data[0] !~ /[0-9]/){ John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/