[Perl] Offer's riddle

Mikhael Goikhman migo at homemail.com
Mon Oct 7 04:28:04 PDT 2002

On 07 Oct 2002 13:18:27 +0200, Shlomo Yona wrote:
> On Mon, 7 Oct 2002, Mikhael Goikhman wrote:
> > > perl -pe'<>' a>b;perl -pe'$_=<>' a>c;
> >   perl -pe'<>'<a>b;perl -pe'$_=<>'<a>c
> it seems that the only difference is the less-than redirection
> of the shell, which does not cause it to hang waiting for input.
> How come this works while the way I though you ment doesn't?
> Perl takes a as the input file in the line I showed, right?
> How does this differ from taking the input from a from standard input?

When you run the first variant, the file "a" is opened by perl and closed
after the first end-of-file, so when the last (odd) <> is proceed, the
current <> handle is not "a" that is closed, but the standard input again.
If you specify more than one file "a1 a2" they will be open consecutively.

In the second variant the input stream exists forever from the perl's
point of view, so it may accept as many end-of-file's on read as needed.


More information about the Perl mailing list