home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ogicse!uwm.edu!cs.utexas.edu!convex!convex!tchrist
- From: tchrist@convex.COM (Tom Christiansen)
- Newsgroups: comp.lang.perl
- Subject: Re: Avoiding intermediate variable
- Message-ID: <1992Aug21.001412.22695@news.eng.convex.com>
- Date: 21 Aug 92 00:14:12 GMT
- Article-I.D.: news.1992Aug21.001412.22695
- References: <MARK.MCINTOSH.92Aug20145545@sombrio.UVic.CA>
- Sender: usenet@news.eng.convex.com (news access account)
- Reply-To: tchrist@convex.COM (Tom Christiansen)
- Organization: Convex Computer Corporation, Colorado Springs, CO
- Lines: 42
- Originator: tchrist@pixel.convex.com
- Nntp-Posting-Host: pixel.convex.com
- X-Disclaimer: This message was written by a user at CONVEX Computer
- Corp. The opinions expressed are those of the user and
- not necessarily those of CONVEX.
-
- From the keyboard of Mark.McIntosh@engr.UVic.CA (Mark McIntosh):
- :Someone out my location would like to avoid the intermediate variable
- :in the following piece of code, assuming $y has been set to some value:
- :
- : $tmp = $y;
- : $tmp =~ s/xy/zz/;
- : print $tmp;
-
- :He wants to retain the value of $y for later use but use a modified
- :version of it once - he won't need it later. Is there a way to do
- :this in Perl without using an intermediate variable?
-
- You can always use
-
- ($tmp = $y) =~ s/xy/zz/;
- print $tmp;
-
- But there's still a temporary. If you tried quite hard, you
- could do
-
- print $y =~ /xy/ && "$`zz$'";
-
- but that seems too obfuscating.
-
- :If not, then we suggest having another form of the "=~" operator (or a
- :function?) which returns the modified value instead of replacing the
- :value in the "operated on" variable. Maybe a "~" operator.
- :
- :eg.
- : print $y ~ s/xy/zz/;
- :
- :Are we crazy? I think this would be useful. Or are we missing something?
-
- Therein lies the awk fallacy. Tilde already has a legimate meaning.
- Usurp it not.
-
- --tom
- --
- Tom Christiansen tchrist@convex.com convex!tchrist
-
- I dunno, I dream in Perl sometimes...
- --Larry Wall in <8538@jpl-devvax.JPL.NASA.GOV>
-