Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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 (Pilgrim) 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?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2015-03-04 00:31 GMT
Find Nodes?
    Voting Booth?

    When putting a smiley right before a closing parenthesis, do you:

    Results (90 votes), past polls