Also, please, for your own sake, add a die clause to
your open line : open FILE, "user/test"
|| die "Can't open file! Perl says '$!'".
Better make it
open FILE, "user/test" or die "Can't open file! Perl says '$!'";
or
open (FILE, "user/test") or die "Can't open file! Perl says '$!'";
or
open (FILE, "user/test") || die "Can't open file! Perl says '$!'";
This is probably one of the most commonly committed Perl coding
errors, made by novices and the reasonably adept alike. In the case of
open FILE, "filename" || die $!; #ERROR - DON'T USE THIS
the || version of 'or' tries to evaluate the thing immediately to its
left, which is the the filename argument, "filename". Since
that string always evaluates to true (in the boolean sense), the
die will NEVER be executed, even if
the
open fails. The
or operator
has a lower precedence than
||, so
it can be used without parenthesis. I suggest using
or for short-circuit
error checks. Providing the args to open & die are correct,
it will always do the right thing.