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

Hello

I have a directory which contains some some text files. I want to open the directory, and then open each text file and run it through a sub with some basic calculations. With this code

#!/usr/bin/perl -w use strict; use warnings; open (Output, ">Output.txt") or die "Can't open"; my $tmp_dir= 'C:\Users\ZB\Desktop\Text Files'; opendir (DIR, $tmp_dir) or die $!; while (my $file_name = readdir(DIR)) { next if $file_name eq '.'; next if $file_name eq '..'; print "$file_name\n"; } close (Output) closedir(DIR);

I have managed to open the directory and print all the file names in Text Files(this is the directory) as output, so at least I am on the right track. But I am struggling to iterate through each text file separately and run it through my sub.

Replies are listed 'Best First'.
Re: Iterate through text files in a directory
by marto (Cardinal) on Jan 08, 2013 at 14:48 UTC

    This looks identical to a question someone else posted minutes ago: Re^2: Open a folder. Very suspicious. Read and understand the replies in the previous thread.

Re: Iterate through text files in a directory
by choroba (Cardinal) on Jan 08, 2013 at 14:48 UTC
    Are you attending the same course or starting a shop together? Open a folder
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Iterate through text files in a directory
by blue_cowdawg (Monsignor) on Jan 08, 2013 at 14:56 UTC

    WTF??? Didn't I already answer this? Do you actually read before you post? I also answered this follow on question that looks identical to your post here.


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

        which makes me wonder if they are the same person...


        Peter L. Berghold -- Unix Professional
        Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg