S
scottcabit
Hi,
I am using a perl program I wrote to search MS Word .doc files for regular expressions using pattern matching. But after 3 days of googling, I cannot find any example where someone actually retrieves the text that is found by the pattern matching!
Here is part of my code:
# The following pattern finds all document numbers
$find->{Text} = m/\d{3}-\d{4}-\d{3}/;
if ($find->Execute()) {
print "The search text was found in $File::Find::name\n";
printf TextFile ("%s\n", $File::Find::name);
# my $output = $find->Found;
# printf TextFile ("%s\n",$find->{Text});
printf TextFile ($1."\n");
} else {
print ".";
}
The line printf TextFile ("%s\n",$find->{Text});
will display the text if it is assigned as a string, not with regular expressions. With regular expressions, it only shows me 1 or 0.
The line printf TextFile ($1."\n");
gives me a warning when run saying: Use of uninitialized value $1 in concatenation (.) or string
So what is the syntax for actually printing the text that was found by the search for a regular expression?
Thanks!
I am using a perl program I wrote to search MS Word .doc files for regular expressions using pattern matching. But after 3 days of googling, I cannot find any example where someone actually retrieves the text that is found by the pattern matching!
Here is part of my code:
# The following pattern finds all document numbers
$find->{Text} = m/\d{3}-\d{4}-\d{3}/;
if ($find->Execute()) {
print "The search text was found in $File::Find::name\n";
printf TextFile ("%s\n", $File::Find::name);
# my $output = $find->Found;
# printf TextFile ("%s\n",$find->{Text});
printf TextFile ($1."\n");
} else {
print ".";
}
The line printf TextFile ("%s\n",$find->{Text});
will display the text if it is assigned as a string, not with regular expressions. With regular expressions, it only shows me 1 or 0.
The line printf TextFile ($1."\n");
gives me a warning when run saying: Use of uninitialized value $1 in concatenation (.) or string
So what is the syntax for actually printing the text that was found by the search for a regular expression?
Thanks!