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

I am debugging a Perl CGI that should give the User an option to upload two files. It always uploads the first file but fails to upload the second. The CGI is on a Solaris and the files to be uploaded are on an NT 4.0 Work station

Here is the code:

while(<$filepath>)

{

print " $_"; # Executes successful

}

while (<$filepath2>) # Can not open the file for reading

{

print "$_";

}

what would possibly be wrong?

  • Comment on reading more than one file in a CGI Script.

Replies are listed 'Best First'.
(jeffa) Re: reading more than one file in a CGI Script.
by jeffa (Bishop) on Aug 28, 2000 at 21:57 UTC
    Did you try reversing the lines that open the files:
    while(<$filepath2>) { print } while(<$filepath>) { print }
    I do need to point out that you shouldn't hard-code your data like such, maybe something more generic would be better:
    foreach (@files2upload) { open F, $_ or die "Yack on file $_\n"; print while(<F>); close F; }
    Jeff
Re: reading more than one file in a CGI Script.
by lhoward (Vicar) on Aug 28, 2000 at 21:43 UTC
    Can you supply more of the currounding code? I've used the CGI module's upload function to have pages that upload multiple files at once and never had a problem.
Re: reading more than one file in a CGI Script.
by xdb19 (Sexton) on Aug 29, 2000 at 19:25 UTC
    I am guessing that you did not open the file. Filepat usually stands for file Path, not the file handle.

    So may I suggest

    open( LOG, $filepath ); while ( <LOG> ) { print } close( LOG );


    another problem might be, if $filePath is a filehandle (which it should be in the first place ), you might be trying to open the same file twice. I have known instances where that fails. so, try closing the file handle after the first one. try this:

    while(<$filepath>) { print " $_"; } close ( $filepath ); while (<$filepath2>) { print "$_"; } close ( $filepath2 );


    see if that helps.

    - Have Fun, XDB19