new variable stupidity

T

Time Waster

OK, i'm being lazy to ask here. :(

I'm always finding myself doing this:
$newvar = $oldvar;
$newvar = s/something/else/;
...because i want both of them. Is there a way to do this in 1 statement?
 
T

Tad J McClellan

Time Waster said:
OK, i'm being lazy to ask here. :(

I'm always finding myself doing this:
$newvar = $oldvar;
$newvar = s/something/else/;
..because i want both of them. Is there a way to do this in 1 statement?


(my $newvar = $oldvar) =~ s/something/else/;
 
B

Ben Morrow

Quoth (e-mail address removed):
I thought that would change $oldvar as well, but it doesn't. Why not?

The return value of (my $newvar = $oldvar) is $newvar, so that's what
gets modified.

Ben
 

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,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top