Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Replace method

by virtualsue (Vicar)
on Mar 13, 2006 at 01:01 UTC ( #536175=note: print w/ replies, xml ) Need Help??


in reply to Replace method

You've received a working answer, now for a little explanation. With the code above, you ended up with $mdl = 1 and $page has its contents clobbered (i.e., changed to "page_name.pl"). Substitution (s///) returns the number of successful matches that occurred, and that's what you (inadvertently) said you wanted.

If you change the code to (my $mdl = $page) =~ s/\.tmpl$/\.pl/;, then the first thing that happens is that $mdl is set to the value of $page, and because it is the left-hand side of the assignment, $mdl then becomes the target of the =~ binding operation. Note the '$' anchor borisz and I added to the regex - this helps ensure you only change what you intend. What if $page = "my.tmplate.tmpl"?


Comment on Re: Replace method
Download Code
Re^2: Replace method
by rsiedl (Friar) on Mar 13, 2006 at 01:20 UTC
    Thanks virtualsue, this was an extremely useful explanation and exactly what i was after. If I could double + I would.
    Cheers.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (12)
As of 2015-07-07 12:32 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 (88 votes), past polls