in reply to Lost hash values
If $x !~ /2005/ you have no $first.... thus $first is undef, meaning during the loop it prints out fine, but inside the hash, you're overwriting the same key everytime.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 "Hash value is $save{$first}\n"; } } } foreach $first (sort keys %save) { if ($save{$first}) { print "hash value is $save{$first} ms.\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Lost hash values
by stephen_isa (Initiate) on May 16, 2005 at 20:54 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |