in reply to how to populate array with lines from text file?
in thread Answer: how to populate array with lines from text file?

my @lines=do{local @ARGV='/path/file';<>};
  • Comment on Answer: how to populate array with lines from text file?

Replies are listed 'Best First'.
Re: Answer: how to populate array with lines from text file?
by japhy (Canon) on Dec 08, 2000 at 18:23 UTC
    Of all ways to put a file's lines in an array, I'm afraid that is one of the most inefficient. Moving data from INSIDE a do { } block to OUTSIDE a do { } block requires copying it, so you're making a list and checking it twice, so to speak.

    If I REALLY needed to put a file into an array (why, I do not know), using the above trick, I'd do:
    my @lines; { local @ARGV = $file; @lines = <> }
    But why should the file be in an array? Ick.

    japhy -- Perl and Regex Hacker