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

You need to remove the line ending when you read it in.
chomp(my @myarray=`cat $myfile`);

The above has problems:

Using Perl's functions and operators would eliminate all of those problems.

open(my $fh, '<', $filename) or die("Unable to open ...: $!\n"); chomp(my @myarray = <$fh>);

If you only need a line at a time, you can use while (<>).

open(my $fh, '<', $filename) or die("Unable to open ...: $!\n"); while (<$fh>) { chomp; ... }

Replies are listed 'Best First'.
Re^2: `cat $myfile`; vs. open(MYHANDLE, "myfile")
by bw (Novice) on Aug 08, 2006 at 17:12 UTC