in reply to Re^2: -p option with __DATA__
in thread -p option with __DATA__

I guess what confuses me is that
perl -MO=Deparse script.pl
and
perl -MO=Deparse < script.pl
give (almost) the same output, but
perl script.pl
hangs as described, whereas
perl < script.pl
prints what I expected.

Replies are listed 'Best First'.
Re^4: -p option with __DATA__
by ikegami (Patriarch) on Nov 21, 2009 at 01:49 UTC

    You shouldn't be surprised that something that reads from STDIN behaves differently when you redirect STDIN than when you don't.

    "<" means "pretend what's in the file is being typed". When you don't specify a file to execute, perl reads the program from the STDIN. It stops reading when it receives and EOF signal or when it sees __END__ or __DATA__.

    If your program proceeds to read from STDIN, so be it. What it reads has nothing to do with whether the program has used __DATA__ or not.

    To show it's got nothing to do with __DATA__:

    BEGIN { print "Enter a line:\n"; print "You entered: ", scalar(<>) } print("a\n"); print("b\n");
    >perl script.pl Enter a line: foo You entered: foo a b >perl < script.pl Enter a line: You entered: print("a\n"); b