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

And the OP can prove this using:
perl -MO=Deparse script.pl
This is tip #6 from Basic debugging checklist.

Replies are listed 'Best First'.
Re^3: -p option with __DATA__
by jdalbec (Deacon) on Nov 21, 2009 at 01:12 UTC
    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.

      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