in reply to Reading a Directory of Files, Searching for Text, Outputting Matches
There are several variables that are used inside the main loop. Are these supposed to be globals? Declaring them with my will make their scope clearer (that might solve part of your problem).use strict;
which is rather unnecessary. It would be simpler to:select directory1; print "$path\n";
Be careful of your opens:print directory1 "$path\n";
Perl will look in the current directory anyway (no need for ./), and you should always test the open. Could be written as:open Contract1, "<./$_ \n"; # What's with the space and new-line? my @lines = <Contract1>; close Contract1; my $contents = join "", @lines;
You place an undef element onto the array, then shift it off:open Contract1, '<', $_ or die "Unable to open $_: $!"; local $/ = undef; # slurp mode my $contents = <Contract1>; # Hope the files are small! close Contract1;
Would be simpler if you did this:@all = undef; shift @all;
Which you would have done if you use strict;my @all;
|
|---|