home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / perl / 5404 < prev    next >
Encoding:
Text File  |  1992-08-20  |  1.5 KB  |  38 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!destroyer!ubc-cs!news.UVic.CA!sirius!Mark.McIntosh
  3. From: Mark.McIntosh@engr.UVic.CA (Mark  McIntosh)
  4. Subject: Avoiding intermediate variable
  5. Message-ID: <MARK.MCINTOSH.92Aug20145545@sombrio.UVic.CA>
  6. Lines: 26
  7. Sender: news@sol.UVic.CA
  8. Nntp-Posting-Host: sombrio.uvic.ca
  9. Organization: University of Victoria, Victoria, BC, Canada
  10. Date: 20 Aug 92 22:55:44 GMT
  11.  
  12. Someone out my location would like to avoid the intermediate variable
  13. in the following piece of code, assuming $y has been set to some value:
  14.  
  15.        $tmp = $y;
  16.        $tmp =~ s/xy/zz/;
  17.        print $tmp;
  18.  
  19. He wants to retain the value of $y for later use but use a modified
  20. version of it once - he won't need it later.  Is there a way to do
  21. this in Perl without using an intermediate variable?
  22.  
  23. If not, then we suggest having another form of the "=~" operator (or a
  24. function?) which returns the modified value instead of replacing the
  25. value in the "operated on" variable.  Maybe a "~" operator.
  26.  
  27. eg.
  28.       print $y ~ s/xy/zz/;
  29.  
  30. Are we crazy?  I think this would be useful.  Or are we missing something?
  31.  
  32. Mark J. McIntosh <Mark.McIntosh@engr.UVic.CA>
  33. ____________________________________________________________________________
  34. University of Victoria, Faculty of Engineering - Dean's Office
  35. Box 3055, Victoria, BC, CANADA    \ "...the mystery of life isn't a problem to
  36. V8W 3P6            (604) 721-6049  \    solve but a reality to experience." 
  37. UUCP: ...!{uw-beaver,ubc-vision}!uvicctr!sirius!mmcintos  \ from Dune
  38.