Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: reading from a file and initializing a variable

by sk (Curate)
on Oct 04, 2005 at 06:58 UTC ( #497144=note: print w/ replies, xml ) Need Help??


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?


Comment on Re: reading from a file and initializing a variable
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://497144]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2015-07-31 10:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (276 votes), past polls