[Perl] Offer's riddle

Shlomo Yona shlomo at cs.haifa.ac.il
Mon Oct 7 04:33:48 PDT 2002

On Mon, 7 Oct 2002, Mikhael Goikhman wrote:

> > > > perl -pe'<>' a>b;perl -pe'$_=<>' a>c;
> > >   perl -pe'<>'<a>b;perl -pe'$_=<>'<a>c
> > 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.

Thanks for the explenations.
That was a nice lesson.

Shlomo Yona
shlomo at cs.haifa.ac.il

More information about the Perl mailing list