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


in reply to reading from a file and initializing a variable

the print statement in the if loops are not getting executed and that where my problem lies

which if are you talking about?

#!/usr/bin/perl -w use strict; my $line = <DATA>; my %hash = (); while ($line) { # and $line ne ""){ chomp($line); if($line =~ /^(\S+)\s+(\d+)$/) { print "inside\n"; $hash{$1} = $2; } $line = <DATA>; } print +($_ , " -> ", $hash{$_},$/) for (keys %hash); __DATA__ $step1 1 $step2 1 $step3 1

Output

inside inside inside $step2 -> 1 $step3 -> 1 $step1 -> 1

Are you sure the data does not contain leading spaces?