in reply to Strange warning message regarding filehandle in an "open" statement

instead of open(INPUT, '$filename') try open(INPUT, "$filename") The double-quotes coax perl to figure out the value of the variable inside the quotes instead of treating it as a literal text string.

Read more on variable interpolation.

Replies are listed 'Best First'.
Re^2: Strange warning message regarding filehandle in an "open" statement
by ikegami (Patriarch) on Sep 24, 2004 at 21:19 UTC

    gah, while open(INPUT, "$filename") is "correct", just use open(INPUT, $filename).

    Better yet, use open(INPUT, '<', $filename) to safely handle inputs of the form >bla or rm -rf / |.

      ikegami's advice is correct. jtgault, Just do away with the quotes.

      Other monks have also advised correctly. The error is precisely because jtgault has declared INPUT via the open command but not used INPUT anywhere further in your program. Do something with that INPUT and that warning will go away.

      And, finally, my advise is also correct (albeit a bit tangential) -- if, jtgault, you use single quotes, you will not be able to open your file, however, if you use double quotes, or as ikegami is suggesting, then you will be successful.

      Update: added "jtgault" so it doesn't seem like I am correcting/advising ikegami when actually I advising jtgault. ;-)