Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: -p option with __DATA__

by jdalbec (Deacon)
on Nov 21, 2009 at 01:12 UTC ( [id://808555]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://808555]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-03-29 14:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found