in reply to `cat $myfile`; vs. open(MYHANDLE, "myfile")

The while (<$file>) approach is usually preferred since it doesn't bloat your memory.

liverpole is correct, but you may still have \r's. Try my @array = split "\r\n" => `cat file`;.

Replies are listed 'Best First'.
Re^2: `cat $myfile`; vs. open(MYHANDLE, "myfile")
by bw (Novice) on Aug 07, 2006 at 22:38 UTC
    Hmmm. No joy for either version. I'll try the while(<MYHANDLE>) approach tommorrow when I return to hit this problem again.

    Thanks to you both for the suggestions.
      What delimits the records in your file? What is the <STDIN> part doing?

      P.S. Use the three argument open if your perl supports it. You may also prefer to use a lexical an indirect filehandle also, e.g., open my $FILE, '<', $file or croak "Could not open '$file': $!";