Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: hash keys from another file

by moritz (Cardinal)
on Mar 23, 2013 at 12:33 UTC ( #1025031=note: print w/ replies, xml ) Need Help??


in reply to hash keys from another file

my @dev; while(<DEV>){ chomp; @dev = <DEV>; }

This almost certainly does not do what you want.

In the while(<DEV>) it reads a line from the file, in the chomp; line it removes the trailing newline, and then in the line @dev = <DEV> it ignores the read line, and reads all the rest of the lines into the array. Without any newline removal.

What you probably meant to write was

while (<DEV>) { chomp; push @dev, $_; }

Or even simpler:

my @dev = <DEV>; chomp @dev;


Comment on Re: hash keys from another file
Select or Download Code
Re^2: hash keys from another file
by Ninke (Novice) on Mar 23, 2013 at 13:03 UTC
    Great, thank you and choroba for explaining me the mistake, now my code serves the purpose:)

      Hmm, Moritz explained you a specific mistake to be corrected. But Choroba told you something that you should not overlook and is at least as important in my view: load the param file into memory (a hash or whatever, depending on the specifics), but don't load the data file in memory if you can avoid it. It is usually far better to iterate over the data line by line when possible. This will save your day when your datafile becomes huge.

Log In?
Username:
Password:

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

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

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (249 votes), past polls