Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Common Perl Pitfalls

by muba (Priest)
on Apr 29, 2012 at 19:32 UTC ( #967968=note: print w/ replies, xml ) Need Help??


in reply to Common Perl Pitfalls

while($string=~ m/reg(ex)/) { $string=~ s/$1/ister/; }

That frightens me a bit. Your substitution replaces the first occurance "ex" with "ister" in the string, no matter whether "ex" is part of "regex" or something else:

my $string = "Sometimes there are extra effects you didn't foresee whe +n using a regex."; while($string=~ m/reg(ex)/) { $string=~ s/$1/ister/; } print $string;

Output:

Sometimes there are istertra effects you didn't foresee when using a r +egister.

Istertra?


Comment on Re: Common Perl Pitfalls
Select or Download Code
Replies are listed 'Best First'.
Re^2: Common Perl Pitfalls
by Joe_ (Beadle) on May 14, 2012 at 22:21 UTC

    You are quite right. It's a terrible mistake on my part. I will edit it.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://967968]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2015-07-29 12:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls