in reply to Re^7: Use of uninitialized value in string eq
in thread Use of uninitialized value in string eq

Why won't that line do what I want? Is there something wrong with the open file statement I'm using? When I try a two-argument open command by assigning $file to a filehandle called INFILE, I get an error message saying: "Useless use of a constant (INFILE) in void context..." In addition, under the copied and pasted code I show in my earlier comment (which does have a 'my $file' at the top not included in the copy and paste), I continue to get an error message saying: "Can't use string ("1000694-R20120314-C20111231-F10-"...) as a symbol ref while "strict refs" is use", referring to the line where my open file command is. This error seems to suggest my code is reading the name of the file as a string instead of the file itself. Any idea how to fix that?

  • Comment on Re^8: Use of uninitialized value in string eq

Replies are listed 'Best First'.
Re^9: Use of uninitialized value in string eq
by SuicideJunkie (Vicar) on Sep 10, 2014 at 18:37 UTC

    Take it piecewise. The part inside the brackets is $file or die "...". That will die if $file is zero or an empty string, or otherwise false.

    Then the result gets given to the open function. open "filename"; doesn't make any sense.

    See open, and use something more like open my $inputFileHandle, '<', $filename or die "can't open $filename for reading: $!\n";