Great for quick and dirty stuff... I use it a lot to translate the output
of one thing into another on the fly.

mysql foo -e 'select bar from foo' | perl -e 'while(<>){chomp;qq`INSERT INTO 
test values("$_");\n`}'|mysql test2

stuff like that... very handy.

On Wed, Feb 01, 2006 at 01:50:59PM -0800, Stephen A. Jarjoura wrote:
> Thanks, Anthony!
> 
> So, localizing '@ARGV' also undefines it, allowing '<>' to be automagically 
> defined as STDIN. Got it.
> 
> Personally, I think I would have written it like this ...
> ===START=CODE===
> sub getParameters {
> my $parm_list = do { local $/; <STDIN> };
> }
> ===END=CODE===
> 
> It reads clearer (to me, at least).
> 
> ~SAJ
> 
> "Anthony R. J. Ball" <[EMAIL PROTECTED]> wrote: 
>   from perldoc perlop
> 
>        The null filehandle <> is special: it can be used to emulate the 
> behavior of sed and awk.
>        Input from <> comes either from standard input, or from each file 
> listed on the command line.
>        Here's how it works: the first time <> is evaluated, the @ARGV array 
> is checked, and if it is
>        empty, $ARGV[0] is set to "-", which when opened gives you standard 
> input.  The @ARGV array is
>        then processed as a list of filenames.  The loop
> 
>            while (<>) {
>                ...                     # code for each line
>            }
> 
>        is equivalent to the following Perl-like pseudo code:
> 
>            unshift(@ARGV, '-') unless @ARGV;
>            while ($ARGV = shift) {
>                open(ARGV, $ARGV);
>                while () {
>                    ...         # code for each line
>                }
>            }
> 
>        except that it isn't so cumbersome to say, and will actually work.  It 
> really does shift the
>        @ARGV array and put the current filename into the $ARGV variable.  It 
> also uses filehandle ARGV
>        internally--<> is just a synonym for , which is magical.  (The pseudo 
> code above doesn't
>        work because it treats  as non-magical.)
> 
>        You can modify @ARGV before the first <> as long as the array ends up 
> containing the list of
>        filenames you really want.  Line numbers ($.)  continue as though the 
> input were one big happy
>        file.  See the example in "eof" in perlfunc for how to reset line 
> numbers on each file.
> 
> 
> On Wed, Feb 01, 2006 at 01:39:06PM -0800, Stephen A. Jarjoura wrote:
> > Hello, all;
> > 
> > I am debugging code written by someone else, and noticed the following:
> > ===START=CODE===
> > sub getParameters {
> >    my $parm_list = do { local(@ARGV,$/); <> };
> > }
> > ===END=CODE===
> > 
> > This does what the author expected (slurp STDIN into the scalar 
> > "$parm_list") but I was surprised by the "<>" as a stand-in for  so I 
> > looked it up. Here is what I found:
> >    http://perldoc.perl.org/perlvar.html
> > ===START=PASTE===
> > ARGV
> > 
> > The special filehandle that iterates over command-line filenames in @ARGV . 
> > Usually written as the null filehandle in the angle operator <> . Note that 
> > currently ARGV only has its magical effect within the <> operator; 
> > elsewhere it is just a plain filehandle corresponding to the last file 
> > opened by <> . In particular, passing \*ARGV as a parameter to a function 
> > that expects a filehandle may not cause your function to automatically read 
> > the contents of all the files in @ARGV .
> > 
> > $ARGV
> > 
> > contains the name of the current file when reading from <>.
> > ===END=PASTE===
> > 
> > I could find no reference to "<>" as a synonym for "" ... am I missing 
> > something obvious? [The code works, so obviously it is my knowledge that is 
> > faulty.] If someone could point me at a reference or doc or faq, I'd be 
> > grateful.
> > 
> > Also, is there any particular reason (in the example given above) why 
> > '@ARGV' would need to be localized, or is the author just being overly 
> > cautous?
> > 
> > Thanks, in advance, for your input!
> > 
> > ---
> > Stephen ~runester~ Jarjoura
> > http://runester.com
> > http://boston.pm.org/kwiki/index.cgi?StephenJarjoura
> > 
> >  
> >  
> > _______________________________________________
> > Boston-pm mailing list
> > [email protected]
> > http://mail.pm.org/mailman/listinfo/boston-pm
> > 
> 
> -- 
>      www.suave.net - Anthony Ball - [EMAIL PROTECTED]
>         OSB - http://rivendell.suave.net/Beer
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> "Now cut that out!!" - Jack Benny
> 
> 
> 
>  
> _______________________________________________
> Boston-pm mailing list
> [email protected]
> http://mail.pm.org/mailman/listinfo/boston-pm
> 

-- 
     www.suave.net - Anthony Ball - [EMAIL PROTECTED]
        OSB - http://rivendell.suave.net/Beer
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Lawyer: a cat who settles disputes between mice.

 
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to