Dan wrote:
> Hi again,
>
> Yet another question for you. I string (these are just examples):
>
> 1) this.is.a.string.to.match.with
> 2) this.is.another.string.to.match.with
> 3) this.is.a.totally.different.string
use strict;
use warnings;
my @string = qw (
this.is.a.string.to.match.with
this.is.another.string.to.match.with
this.is.a.totally.different.string
);
> Basically, what I want to be able to do, is to carry out match testing
> against them, and return just the strings that match. For example, a
> search of *.with returns strings 1 and 2
> a search of *string* returns strings 1 and 2
> a search of *a* returns all 3
> a search of *.a.* returns 1 and 3
> I think you should get the idea.
foreach my $pattern (qr(\.with), qr(string), qr(a), qr(\.a\.)) {
foreach my $i (0 .. $#string) {
print $i+1, " " if $string[$i] =~ $pattern;
}
print "\n";
}
> I'm no master on regex, so I'd have absolutely no idea where to
> start. All help muchly appreciated.
Output:
1 2
1 2 3 (You see, 'string' appears in all 3 strings!)
1 2 3
1 3
I'll explain tomorrow if you need me to. Bed time now :)
Cheers,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]