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

I currently import and parse each line of a file using the CGI module filefield() form input with the following code:

my $file=param('upload');
while (<$file>)
{code to handle import}

I now need just to have a second file of the same format just continue coming in like it is part of the first stream. Is there a quick method to make this 'while' loop just continue into the second file?
  • Comment on Combine two plus files for parsing during import

Replies are listed 'Best First'.
Re: Combine two plus files for parsing during import
by loikiolki (Novice) on Feb 08, 2006 at 04:13 UTC

    If I understand your intentions correctly, you mean to append the contents of a second file to the end of the output stream provided by the uploaded file. If so, there are a few different ways of arriving at such a result. Here's one of them that doesn't require anything fancy.

    my $q = CGI->new(); my $upload = $q->upload('upload'); open(my $second, '<', 'second_file.dat') or die($!); open(my $out, '>', 'output.dat') or die($!); for my $fh ($upload, $second) { print $out $_ while <$fh>; }
Re: Combine two plus files for parsing during import
by GrandFather (Saint) on Feb 08, 2006 at 02:57 UTC

    Do you mean:

    local @ARGV = ('firstFile.txt', 'secondFile.txt'); while (<>) { # do stuff with firstFile.txt then secondFile.txt }

    DWIM is Perl's answer to Gödel