Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^2: <> oddity ?

by hdb (Prior)
on Mar 27, 2013 at 10:31 UTC ( #1025669=note: print w/ replies, xml ) Need Help??

in reply to Re: <> oddity ?
in thread <> oddity ?

If you call the code below,

while(<>) { print; }

then all three commands below result in the same output:

$ perl $ perl < $ cat | perl

Comment on Re^2: <> oddity ?
Select or Download Code
Replies are listed 'Best First'.
Re^3: <> oddity ?
by LanX (Canon) on Mar 27, 2013 at 10:48 UTC
    you're right

    from 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 (<ARGV>) { ... # code for each line } }

    Cheers Rolf

    ( addicted to the Perl Programming Language)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1025669]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2015-10-09 23:10 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (253 votes), past polls