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 | |
|
Re: Iterate through text files in a directory
by choroba (Cardinal) on Jan 08, 2013 at 14:48 UTC | |
|
Re: Iterate through text files in a directory
by blue_cowdawg (Monsignor) on Jan 08, 2013 at 14:56 UTC | |
by marto (Cardinal) on Jan 08, 2013 at 15:02 UTC | |
by blue_cowdawg (Monsignor) on Jan 08, 2013 at 15:20 UTC |