IL PROTECTED]>, "Beginners (E-mail)"
<[EMAIL PROTECTED]>
Subject: RE: grep a array element..
Please do... I thought using qr// to store REs in variables speed up since
it gets compiled once instead of over and over again.
> -Original Message-
> From: Jeff &
Janceski
> Cc: '[EMAIL PROTECTED]'; Beginners (E-mail)
> Subject: RE: grep a array element..
>
>
> On Apr 16, Nikola Janceski said:
>
> >Yes but only if you are looking for that pattern.. if
> you wanted to add
> >something like "sedan" then
On Apr 16, Nikola Janceski said:
>Yes but only if you are looking for that pattern.. if you wanted to add
>something like "sedan" then you need to use // but the qr would speed up the
>compile when using a $var in the //;
>
>if($element =~ $lookfor) { ## works if $lookfor = qr/car/; the same
On Apr 16, David Gray said:
>> my $lookfor = qr/car/; # this is faster and you don't even
>> need to put in the //
>
>> > if ($element =~ /$lookfor/) {
>
>Are you saying the if inside the foreach could be written as:
>
>if($element =~ $lookfor) {
>
>If the search string is defined with qr//?
f($element =~ /sedan $lookfor/) { ## works faster if $lookfor = qr/car/;
than if $lookfor = "car";
> -Original Message-
> From: David Gray [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, April 16, 2002 11:41 AM
> To: [EMAIL PROTECTED]; 'Nikola Janceski'
> Sub
> uh...
>
> my $lookfor = qr/car/; # this is faster and you don't even
> need to put in the //
> > ---
> > use strict;
> >
> > my @array = qw(car bus caravan bike cart);
> >
> > my $lookfor = "car";
> >
> > foreach my $element (@array) {
> > if ($element =~ /$lookfor/) {
> > prin
uh...
my $lookfor = qr/car/; # this is faster and you don't even need to put in
the //
> -Original Message-
> From: John Edwards [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, April 16, 2002 9:42 AM
> To: '[EMAIL PROTECTED]'; [EMAIL PROTECTED]
> Sub
You mean something like this?
---
use strict;
my @array = qw(car bus caravan bike cart);
my $lookfor = "car";
foreach my $element (@array) {
if ($element =~ /$lookfor/) {
print "Found a match!! => $element\n";
} else {
print "$lookfor doesn't match $element\n";
}
}