Assigning pattern matches to an array
- From: "Graham Stow" <graham@xxxxxxxxxxxx>
- Date: Sat, 30 Dec 2006 12:58:59 -0000
The following is a crude attempt at matching occurrences of email addresses
within files in a directory. However, I can't figure out why line 15 doesn't
assign the pattern matches to the @matches array. Any ideas gang, or have I
been eating too much turkey?
#!/usr/local/bin/perl
use File::Find;
@directories = ("c:/email2");
find (\&wanted, @directories);
sub wanted {
$filename=$File::Find::name;
if ($filename =~ /\.\w{3}$/) {
push(@files, $filename);
}
}
foreach $file (@files) {
open (DATA, "$file") || die "Error opening $file\n";
@whole_file = <DATA>;
foreach $line (@whole_file) {
@matches = /\b\w+@\w+\b/g;
}
close DATA || die "Unable to close $file\n";
# closes the current file
}
foreach $match (@matches) {
print "$match\n";
}
$count += @matches;
print "$count matches\n";
.
- Follow-Ups:
- Re: Assigning pattern matches to an array
- From: Dr.Ruud
- Re: Assigning pattern matches to an array
- From: John W. Krahn
- Re: Assigning pattern matches to an array
- Prev by Date: Re: Superformula with Perl?
- Next by Date: FAQ 4.64 How can I get the unique keys from two hashes?
- Previous by thread: FAQ 5.17 How can I open a file with a leading ">" or trailing blanks?
- Next by thread: Re: Assigning pattern matches to an array
- Index(es):
Relevant Pages
|