LPM: Scope of $_

David Hempy hempy at ket.org
Tue Jan 11 22:51:39 CST 2000


At 10:05 PM 1/11/2000 -0500, you wrote:
>> 
>> So you tell me...am I confused or disappointed?  
>
>You're disappointed, and rightly so.  

Thanks for the reference.  I read the Sins page with great interest.

Now that I understand the problem, I'm going to apply a bit of both
suggestions.  I have changed my module from:


>sub rtf2html { 
> $_ = shift; 
> my ($outfile) = @_; 

...to:

>sub rtf2html { 
> local $_ = shift; 
> my ($outfile) = @_; 

This has fixed the problem of the caller's $_ being stomped.  Or more
accurately, it restores the value of the only $_ after the sub block ends.
I started to localize $_ around call to rtf2thml, but realized this really
belongs in the module itself to be socially acceptable.


I still plan on using $_ for tight little loops 'cause it's so darned
nifty.  But I will go ahead and use my variables any time I have to scroll
to find end of the loop!  ;-)


Thanks for the help, all!

-dave


---------------------------------------------------------------------------
David Hempy          --   USUA Region 6 Representative        (KY-IN-MI-OH)
ASC Trike BFI #BKY56 --   FAA Aviation Safety Counselor   --    EAA #456510
<hempy at ket.org>      --   www.davidhempy.com              --    (c)2000,DBH
Views expressed are not those of ASC, FAA or USUA unless explicitly stated.
---------------------------------------------------------------------------




More information about the Lexington-pm mailing list