Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Perl: the Markov chain saw
 
PerlMonks  

Re: Putting files in an Array

by cheekuperl (Monk)
on Jul 11, 2012 at 15:17 UTC ( #981154=note: print w/ replies, xml ) Need Help??


in reply to Putting files in an Array

I am trying to put each line of a text file in an array
All you need is this (after opening the file):

@lines=<FILEHANDLE> #slurp it
But I see your code conditionally pushes elements into array. Nothing seems wrong with the code. Two things:
1) Open file statement is missing.
2) Instead of using $_ everywhere, use your own variable.


Comment on Re: Putting files in an Array
Download Code
Re^2: Putting files in an Array
by monsoon (Monk) on Jul 11, 2012 at 15:27 UTC
    It looks like there's no need to open the file here, because the filename is in the @ARGV. It is as if it comes from STDIN. In this case this works @lines=<>;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2014-04-17 05:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (440 votes), past polls