Re: Assigning pattern matches to an array




"John W. Krahn" <someone@xxxxxxxxxxx> wrote in message
news:Vsxlh.96488$YV4.8365@xxxxxxxxxxx
Graham Stow wrote:
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 warnings;
use strict;

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;

That line is short for:

@matches = $_ =~ /\b\w+@\w+\b/g;

But the current line is in $line not in $_ so you have to do:

@matches = $line =~ /\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";




John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
Makes sense John, but doesn't work -I still get 0 matches (and I'm certain I
should be getting some).
Graham


.