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 as $element =~ /car/ if($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' > Subject: RE: grep a array element.. > > > > 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/) { > > > print "Found a match!! => $element\n"; > > > } else { > > > print "$lookfor doesn't match $element\n"; > > > } > > > } > > Are you saying the if inside the foreach could be written as: > > if($element =~ $lookfor) { > > If the search string is defined with qr//? > > -dave > > ---------------------------------------------------------------------------- -------------------- The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]