[comp.lang.perl] Request concerning __END__

jv@mh.nl (Johan Vromans) (09/12/90)

Is it a weird idea to always treat lines following __END__ as input
for the program, even if the program itself is not read from standard
input?

E.g. assume "t.pl" is executable and contains

    #!/usr/bin/perl
    while ( <> ) {
	print "-> $_";
    }
    __END__
    data1
    data2

Then "perl < t.pl" works, but "perl t.pl" and "t.pl" do not.

	Johan
-- 
Johan Vromans				       jv@mh.nl via internet backbones
Multihouse Automatisering bv		       uucp: ..!{uunet,hp4nl}!mh.nl!jv
Doesburgweg 7, 2803 PL Gouda, The Netherlands  phone/fax: +31 1820 62911/62500
------------------------ "Arms are made for hugging" -------------------------

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (09/13/90)

In article <1990Sep12.152018.2904@squirrel.mh.nl> Johan Vromans <jv@mh.nl> writes:
: Is it a weird idea to always treat lines following __END__ as input
: for the program, even if the program itself is not read from standard
: input?

Better not be weird.  I already implemented it.

: E.g. assume "t.pl" is executable and contains
: 
:     #!/usr/bin/perl
:     while ( <> ) {
: 	print "-> $_";
:     }
:     __END__
:     data1
:     data2
: 
: Then "perl < t.pl" works, but "perl t.pl" and "t.pl" do not.

After the next patch, say

     #!/usr/bin/perl
     while ( <DATA> ) {
 	print "-> $_";
     }
     __END__
     data1
     data2

and it will work all the time.  Note that this is upward compatible since
we're reading off a filehandle that hasn't been explicitly opened.

Larry