>>>>> "ARJB" == Anthony R J Ball <[EMAIL PROTECTED]> writes:
ARJB> Great for quick and dirty stuff... I use it a lot to translate
ARJB> the output of one thing into another on the fly.
ARJB> mysql foo -e 'select bar from foo' | perl -e
ARJB> 'while(<>){chomp;qq`INSERT INTO test values("$_");\n`}'|mysql
ARJB> test2
that is a waste of keystrokes. use the -n or -p options to make a
command line loop over all the lines. and with -l you get auto chomping
as well. also i don't see any output from that perl -e (or i could be
blind). did you miss a print or something?
<untested and i guess the above was pseudo code>
perl -lne 'print qq{INSERT INTO test values("$_");\n}'
or with -p (which prints $_ after each loop iteration):
perl -lpe '$_ = qq{INSERT INTO test values("$_");\n}'
and because each line in in $_ you can do s/// and such directly on each
line.
and -p/-n loops translates into <> internally. see perldoc perlrun for
the details on them.
as for the OP, <> is not an alias for <STDIN>. note what the docs said,
it loops over lines the FILES in @ARGV. if you don't pass any args in
@ARGV (or you consume them in a BEGIN block that say parses options)
then <> will read from stdin. <STDIN> will only ever read from
stdin. and the filename - is also an alias for stdin so if that was
passed in @ARGV it would read <STDIN> when - is opened.
the purpose of <> is to allow perl to easily be used in pipelines like
the example shown above. it can input from file args or stdin like many
of the standard unix stream tools can. the -n and -p options make <>
available to the command line without the extra code as i showed.
uri
--
Uri Guttman ------ [EMAIL PROTECTED] -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm