Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I am using my variable as
my $file_upload="$dir_details->{WORK_DIR}/upload/$params->{upname}.dat +";
and want to read n lines from $file_upload. What I have used is
$file_next = (perl -ple "exit if $. > 10" $file_upload);
but I am getting sofware error here. Please help.

Jhum

update (broquaint): added formatting

Replies are listed 'Best First'.
Re: Reading n lines/records from a file
by tilly (Archbishop) on May 14, 2003 at 17:39 UTC
    And what is to stop someone from sticking "interesting stuff" into the upname parameter, causing them to get into things that they shouldn't?

    Read up on the poison null byte attack and note that someone who knew how could readily start reading your /etc/passwd file, from which they could run crack to start figuring out how to break into your server...

    Yes, I know that you probably didn't know about this. But the people who come looking around to see if they can root your machine sure do, which is why it is important to point it out to you.

Re: Reading n lines/records from a file
by halley (Prior) on May 14, 2003 at 17:03 UTC
Re: Reading n lines/records from a file
by flounder99 (Friar) on May 14, 2003 at 18:28 UTC
    You could use backticks to call out to perl by simply changing your code to something like this:
    $file_next = `perl -ple 'exit if \$. > 10' $file_upload`;
    (note the escaping, this would also be shell dependent. I don't think this would work on windows) but that is pretty inefficient because is involves starting another process. I would just do something simple and easy to read and maintain like this:
    # # define $file_upload, etc above this # open INFILE, $file_upload or die $!; # or do something more graceful my $file_next; for (1 .. 10) { $file_next .= <INFILE>; } close INFILE;

    --

    flounder