in reply to Perl to executable conversion error

The code fragment appears to be wrong.

Try this:

my $filename = <STDIN>; chomp($filename); open (FH,$filename) or die "Unable to open file: $!"; my @Lines = <FH>; close FH;

You should also check your return values when attempting to open files otherwise it could silently fail and then fall over later when the code you expect isn't there... The $! is very handy for rooting out why something won't open.

I didn't manage to get it to throw the error you came up with so perhaps where Perl is reporting isn't actually the root of the problem (which is fairly common with most programming languages!).

--- Jay

All code is untested unless otherwise stated.

Replies are listed 'Best First'.
Re^2: Perl to executable conversion error
by herveus (Prior) on Oct 07, 2004 at 13:12 UTC
    Howdy!

    Why is the chomp needed? Remember, open does magical things...

    My test execution of the code as proffered (wrapped with use strict, use warnings, and a print @Lines at the end) yielded no errors.

    Now, there are security implications in using raw input as a filename in a two-argument open, but the code as presented does work.

    yours,
    Michael