Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

RE: RE: RE: RE: Selective substitution: not in Perl?

by merlyn (Sage)
on Aug 16, 2000 at 15:33 UTC ( [id://28097]=note: print w/replies, xml ) Need Help??


in reply to RE: RE: RE: Selective substitution: not in Perl?
in thread Selective substitution: not in Perl?

To make it even clearer, remember that the right side of the s///ge can be an arbitrary block. Here's the "Perl Bowling" style written for clarity:
{ my $count = 0; $string =~ s{($pattern)}{ my $source = $1; $count++; if ($count == $target) { $source = $replacement; # replace! } $source; # either original or replacement now }ge; };
And yes, you can actually write it like that, just as you see. If you're doing anything odd in the right hand side in a s///e, I recommend expanding it out like that.

-- Randal L. Schwartz, Perl hacker

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-19 00:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found