in reply to Re^3: -p option with __DATA__
in thread -p option with __DATA__
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
|
|---|