home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!destroyer!ubc-cs!news.UVic.CA!sirius!Mark.McIntosh
- From: Mark.McIntosh@engr.UVic.CA (Mark McIntosh)
- Subject: Avoiding intermediate variable
- Message-ID: <MARK.MCINTOSH.92Aug20145545@sombrio.UVic.CA>
- Lines: 26
- Sender: news@sol.UVic.CA
- Nntp-Posting-Host: sombrio.uvic.ca
- Organization: University of Victoria, Victoria, BC, Canada
- Date: 20 Aug 92 22:55:44 GMT
-
- 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?
-
- 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?
-
- Mark J. McIntosh <Mark.McIntosh@engr.UVic.CA>
- ____________________________________________________________________________
- University of Victoria, Faculty of Engineering - Dean's Office
- Box 3055, Victoria, BC, CANADA \ "...the mystery of life isn't a problem to
- V8W 3P6 (604) 721-6049 \ solve but a reality to experience."
- UUCP: ...!{uw-beaver,ubc-vision}!uvicctr!sirius!mmcintos \ from Dune
-