Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uwm.edu!ogicse!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal L. Schwartz) Newsgroups: comp.lang.perl Subject: Re: when is pass by reference necessary? Message-ID: <1991Mar28.215043.5288@iwarp.intel.com> Date: 28 Mar 91 21:50:43 GMT References: <1991Mar28.053132.7061@yarra-glen.aaii.oz.au> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal L. Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 31 In-Reply-To: pem@yarra-glen.aaii.oz.au (Paul E. Maisano) In article <1991Mar28.053132.7061@yarra-glen.aaii.oz.au>, pem@yarra-glen (Paul E. Maisano) writes: | When I wrote this, I intended to pass the file handle as *X but I forgot | the *. It still worked so I wondered if I was confused about why I thought | the * was necessary. Is it necessary ? What's happening is that the 'X' is being passed as a literal string, as if you had said &my_open("X", "file.dat"); and then in the assignment within the subroutine: local(*F, $name) = @_; you are assigning: *F = "X"; which is the same as: *F = *X; except that the "X" is looked up at runtime. So, it is *safe* (at least in this case... don't overgeneralize!), but *inefficient*. print join(" ",("Perl","another","Just","hacker,")[2,1,0,3]) -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/