Can I simplify this?

S

Steve Hémond

Hi people,

I want each line of a file to be checked for occurences :

if ($line =~ /x/ || $line =~ /\b[Tt]he\b/)
{
print "$a $line";
$a++;
}

if any 'x' or any 'the' or 'The' word is found in the line, I print the line
number.

Is there any way I can simplify this line? :

if ($line =~ /x/ || $line =~ /\b[Tt]he\b/)



Thanks in advance,

Steve
 
F

Frank Maas

Gunnar Hjalmarsson said:
Steve said:
Is there any way I can simplify this line? :

if ($line =~ /x/ || $line =~ /\b[Tt]he\b/)

if ($line =~ /x|\b[Tt]he\b/)

But be warned. The 'bible' ('Programming Perl', 3rd ed) says on
page 595 that the || alternative is often faster due to the way
the regex optimizer works. You might want to try it out first...

--Frank
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top