in reply to Re: Grep file before sending through socket
in thread Grep file before sending through socket

dws,
Thanks, this works. I was wondering if you could help me interpret the following line.
my $file = do { local $/; <FILE> };
I know $/ is a line separator, but in this context, what is it doing? I'm fairly new to perl and some things are still cryptic to me. Thanks

Replies are listed 'Best First'.
Re: Re: Re: Grep file before sending through socket
by dws (Chancellor) on Dec 11, 2001 at 22:45 UTC
    I was wondering if you could help me interpret the following line.   my $file = do { local $/; <FILE> }; This is called "slurp mode". Setting $/ to undef means that the entire file will be read. Localizing $/ within a short-lived scope both sets $/ to undef, and ensures that it will be restored on scope exit.

    This is equivalent in effect to writing   my $file = join('', <FILE>); but without the extra overhead to build up a temporary array and set of strings to populate it with.