http://www.perlmonks.org?node_id=457544

stephen_isa has asked for the wisdom of the Perl Monks concerning the following question:

Hi, The following hash prints all the values(total 81) alright on line16(commented) of the code below but prints only 12 values in the final foreach loop. Any clues? Thanks.
#!/usr/bin/perl -w open FILE1,"out.prod" or die "Cannot open file $!"; @rec=<FILE1>; %save=(); foreach $x (@rec){ if ( $x =~ /2005/ ){ chomp($first=$x); $save{$first}=undef;} if ( $x =~ /time/ ){ chomp($lat= $x); $lat =~ s/.*?time=(\d+)\.\sms$/$1/; if( $lat > "10" ){ $save{$first}=$lat; #print "$first is $save{$first}\n"; } } } foreach $first (sort keys %save){ if ($save{$first}){ print "$first is $save{$first} ms.\n"; } }