Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Answer: How do I assign & substitute in one statement?

by Roy Johnson (Monsignor)
on Nov 13, 2004 at 15:16 UTC ( [id://407608]=note: print w/replies, xml ) Need Help??


in reply to Re: How do I assign & substitute in one statement?
in thread How do I assign & substitute in one statement?

Important thing I overlooked: your solution modifies $sBegin!

You would need to create a copy before modifying. One way:

($sEnd) = map {s/hello/goodbye/g; $_;} map {$_} ($sBegin);
Another:
($sEnd) = map {s/hello/goodbye/g; $_;} @{[$sBegin]};
A functionally similar solution that doesn't use map:
$sEnd = do {local $_ = $sBegin; s/hello/goodbye/g; $_;};
Of course, creating a copy and working on it is the canonical solution:
(my $sEnd = $sBegin) =~ s/hello/goodbye/g;
This couldn't be used in a combination declaration-assignment, though, while the others could.

Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-03-28 20:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found