in reply to text file parsing
find sub { my $numb = (fileparse($_,'.txt'))[0]; return unless $numb =~ /^\d+$/; push @ARGV, $File::Find::name if $numb >= $start and $numb <= $end; }, $dir;
Basically, this code goes to a directory and read all the files in it.Sounds like a job for readdir.
but that's just one suggestion. It seems to me that using File::Find is somewhat overkill for this problem as File::Find will happily recurse your entire directory tree and that might take quite some time.opendir DIR, $dir or die "Failed to open directory $dir: $!"; foreach my $file (readdir DIR) { # much the same as using fileparse my ($number, $ext) = split /\./, basename($file); next unless $ext eq "txt"; next unless $number =~ /^\d+$/; next unless $number < $start || $number > $end; push @ARGV, "$dir/$file"; }
Of course if you need it to recurse your directory tree then readdir will be useless and you've chosen the correct tool.
If you're certain that the problem does not lie in your call to find, perhaps you should print out @ARGV and have a look at its contents. Something like:
should do the trick nicely.{ local $, = "\n"; print @ARGC; }
Note that when you print in your while loop at the bottom you're concatenating all the files together when they were originally separate. So if @ARGV ended up containing 10 files then your output will be all 10 files concatenated after the substitution.
Hope this helps.
jarich
|
|---|