Perl optimisation help

david thornton david-FkEgs2FKm2NvBvnq28/GKQ at public.gmane.org
Fri Jun 23 00:48:07 UTC 2006


G. Matthew Rice wrote:

>david thornton <david-FkEgs2FKm2NvBvnq28/GKQ at public.gmane.org> writes:
>  
>
>>>Faster would be
>>>
>>>   { local $/; $var = <INPUT>; }
>>>      
>>>
>>I realize there's not much to it, but can you walk us through "local $/" ? I
>>love brief code, just it's sometimes hard to understand.
>>    
>>
>
>Well, let's break it up:
>
>{                 # Start a new block (and new scope)
>  local $/;       # Define a locally scoped variable called $/ initialized to
>                  # undef.  This is the 'input record separator' which is
>                  # a '\n' by default.
>  $var = <INPUT>; # Since 'nothing' separates records, the first read will
>                  # read in everything.
>}                 # end of scope; $/ goes back to whatever it was before. 
>
>You should do a little reading up on what 'local' means, too.  There are a
>number of scopes for variables in perl; global, local, my, our. (did I miss
>any?).
>
>HTH,
>  
>
genius! thanks for that.
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list