Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > new variable stupidity

Reply
Thread Tools

new variable stupidity

 
 
Time Waster
Guest
Posts: n/a
 
      02-23-2008
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?
 
Reply With Quote
 
 
 
 
Tad J McClellan
Guest
Posts: n/a
 
      02-23-2008
Time Waster <> wrote:
> 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/;


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      02-25-2008

Quoth :
> On 2008-02-23, Tad J McClellan <> wrote:
> >
> > (my $newvar = $oldvar) =~ s/something/else/;
> >

> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
New Age Jobs offed himself (through stupidity) RichA Digital Photography 4 10-28-2011 09:25 AM
OT: Thursday Stupidity Briscobar MCSE 11 06-30-2005 10:28 PM
in the valley of spam stupidity on spam removing nota chance Computer Support 4 08-08-2004 10:44 PM
grasping a Usenet stupidity anthonyberet Computer Support 3 05-28-2004 06:30 AM
FINALLY FIXED (That's to the stupidity on my part) MatGyver Cisco 0 10-29-2003 09:48 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57