in reply to Creating an array from a text file

my @array = do {local @ARGV = "yourfile"; <>};
Abigail

Replies are listed 'Best First'.
Re: Re: Creating an array from a text file
by Ovid (Cardinal) on Aug 13, 2002 at 15:58 UTC

    Okay, I have to ask: was that just tongue-in-cheek, or do you see some benefit to potentially confusing the poor seeker? :)

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

      Reading in a file into an array is a pretty basic thing to do in Perl. In fact, if you don't know this standard idiom, you shouldn't be programming - you should be studying. So, if my solution causes the seeker to fetch the manuals ago, all the better. If he doesn't and all he wants is something delivered on a silver platter, then I don't want to spend more than one line in giving an answer - and I didn't while my answer was correct and not inefficient.

      And besides, it's an idiom I sometimes use myself. It's faster to code than the open/read/close lines.

      Abigail