Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

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.

Replies are listed 'Best First'.
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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2018-03-18 06:51 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (228 votes). Check out past polls.