Perl optimisation help
G. Matthew Rice
matt-s/rLXaiAEBtBDgjK7y7TUQ at public.gmane.org
Thu Jun 22 22:13:45 UTC 2006
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,
--
g. matthew rice <matt-s/rLXaiAEBtBDgjK7y7TUQ at public.gmane.org> starnix, toronto, ontario, ca
phone: 647.722.5301 x242 gpg id: EF9AAD20
http://www.starnix.com professional linux services & products
--
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