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

Re: Getting variables from file

by GrandFather (Cardinal)
on Jan 31, 2011 at 02:48 UTC ( #885192=note: print w/ replies, xml ) Need Help??


in reply to Getting variables from file

Are you expecting to read multiple lines from the input file or just one? If you intend to read multiple lines and thus (I guess) generate multiple forms put the print lines inside the loop (although there are much better ways to do this).

If you expect to read a single line then replace the loop (and the few lines before it) with:

my $file = '...'; open my $inFile, '<', $file or die "Can't open $file: $!"; my $line = <$inFile>; chomp $line; my ($name1, $name2, $address, $phone) = split("\t"); close($inFile);

As an aside, notice the use of the three parameter version of open and the use of a lexical file handle. Note too the check on the result of the open.

True laziness is hard work


Comment on Re: Getting variables from file
Download Code
Re^2: Getting variables from file
by thezip (Vicar) on Jan 31, 2011 at 04:31 UTC

    Grandfather,

    I must admit that I'm checking the results of system calls less and less these days, thanks to Paul Fenwick's wonderful autodie module.

    It is quite impressive, and removes the necessity of a whole bunch of error checking.

    I especially like the Klingon programming proverb... ;-)



    What can be asserted without proof can be dismissed without proof. - Christopher Hitchens

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (15)
As of 2014-08-27 20:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (252 votes), past polls