Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: files

by SarahM (Monk)
on Jun 13, 2002 at 20:50 UTC ( [id://174339]=note: print w/replies, xml ) Need Help??


in reply to Read and Combine Range of Two Files (was files)

You can use magic! Just have the first parameter be the file you want to save to, and then just list all the files you want to read from.

Here is an example

#!/usr/local/bin/perl my $outfile = shift; # You have to use shift here for magic to work open (OUT, ">$outfile") || die $!; while (<>){ # This is magic, it opens all the files that are on @ARGV print OUT $_; } close (OUT);
You would call it like this 'myprog.pl outfile file1 file2 file3'

Replies are listed 'Best First'.
Re: Re: files
by A_CAR11 (Initiate) on Jun 14, 2002 at 19:43 UTC
    What if you would have the files been selected from a select menu. Like one dropdown with one file name and another with the other file name using a form to submit the information and display results to the browser window?
      That is different, but it isn't too hard...first, you need to use CGI.pm, then you get a list of the files, open them and write them out to another file. Here is an example...your webform will need one input named 'outfile' for the file you want to save to. You will also need a series of inputs named 'fileX' where 'X' is a number, one for each input file.

      WARNING!!! This example doesn't use taint in order to make it more readable. In a real script you should always use taint.

      use CGI; my $q = new CGI; # Get a CGI object open (OUT, ">$q->param('outfile')") || die $!; # Open our output file my @files = grep{/^file\d+$/} $q->param(); # Grab a list of params for my $filename (@files){ open (IN, $q->param($filename)) || die $!; # Open each input file print OUT <IN>; # Print the input file to the output file close (IN); # Make sure you close the input file } close (OUT);
        Ok. But the interface for this program has two select menus that read the directory where the files are stored and they're dynamically populated on each select menu. From there one choice of file is made from one of the select menu and other from the other select menu, by clicking on the submit bottom the code behind will process the range of the files selected and it will get displayed to the browser. Thank you so far, sorry if I am driving you crazy with this. Just want to get this clear as possible.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://174339]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-19 20:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found