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

I want to process distinct files in a certain directory. The respect filenames are stored in a list. How can I process all respect files stored in the list? Please help!

Replies are listed 'Best First'.
Re: processing files
by si_lence (Deacon) on Dec 06, 2004 at 18:24 UTC
    I'm not too sure what you want to achieve, but
    if you mean that your filenames are stored in an array
    you can do something like this:
    my @files=qw(file1 file2) ; #or however you get your filenames foreach my $filename (@files) { #do something with the file print "$filename \n"; }
    si_lence
      I am using the follwing code, but obviously it is processing the first file twice. Do you have any idea why it is doing that and what is wrong with my code?
      foreach $file (@files){ open(IN, "$file") or die ("Cannot open file $file!\n"); $promnum = 0; $stop = 0; while ($stop == 0){ while (<IN>) {....
Re: processing files
by bass_warrior (Beadle) on Dec 06, 2004 at 18:26 UTC
    use strict; my $filelist = "/foo/bar/file.txt" open(FILE, $filelist) or die "$!\n"; while(<FILE>) { chomp; open(FILE2, $_) or die "$!\n"; <do whatever> close; } close;

    This is assuming one filename per line.
      You should say close(FILE2) and close(FILE), because close does not look at $_ to see what should be closed, it closes the currently selected filehandle ($_ gets clobbered in your while-loop, anyway).