Re: __END__ without __BEGIN__?
by merlyn (Sage) on Mar 29, 2005 at 20:52 UTC
|
Assuming this isn't a troll...
Are you presuming the Perl compiler is psychic? How would it know that "b@d" at the beginning is to be skipped over? The current compiler is single pass... only once over the input file (which is why you can pipe a script from STDIN).
| [reply] |
|
No troll, just curious. Still...Even presuming the compiler is not phsycic, why can't you have a tag that says "forget what you have seen up to this point", when you have one that says "ignore the rest of the file?"
| [reply] |
|
There is such a construct if you use the -x switch:
>perl -x <<END
bla bla bla ignored
#!perl
stuff_to_execute();
__END__
bla bla
END
updated: s/<END/<<END/
| [reply] [d/l] [select] |
|
|
|
|
|
You could probably do that (more or less) using source filters.
use Filter::ignore-until-BEGIN-token;
b@d
__BEGIN__
print 'ignore b@d';
die;
Now all that has to be done is writing the Filter::ignore-until-BEGIN-token-filter. We will leave that as an exercise for the reader. ;-)
CountZero "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law
| [reply] [d/l] [select] |
|
| [reply] |
|
Re: __END__ without __BEGIN__?
by moot (Chaplain) on Mar 29, 2005 at 21:26 UTC
|
For one thing, it would make the compiler slower and less stable. Consider:
BEGIN {
my $var = do_some_processing();
}
__BEGIN__
# start of real processing.. but the compiler has already processed th
+e BEGIN block!
# ..real code here..
The compiler would have to forget everything it did in the BEGIN block, and if there were side effects (for example, writing to files), all of that would have to be undone.
I suppose your hypothetical __BEGIN__ tag could cause the compiler to simply ignore everything until such a tag is seen.. but what if the tag doesn't exist? the compiler would have to either re-read the file (breaking STDIN, as per merlyn's comment Re: __END__ without __BEGIN__? above), or would have to store a potentially enormous file (plus dependencies) in memory before compilation could truly begin*. This issue doesn't exist with __END__ because the compiler can fall off the end of the file and thus not need to see an __END__ tag.
Of course this could all be complete hooey. Larry may have just left out __BEGIN__ because to include it would be extra work ;)
* - It might do this already, but without the __BEGIN__ tag compilation can begin as soon as perl figures out it has something to work with, which is at least potentially faster.
Update: changed 'more unstable' to 'less stable' - did not mean to imply the compiler was already unstable ;) | [reply] [d/l] |
|
| [reply] |
|
| [reply] |
Re: __END__ without __BEGIN__?
by gaal (Parson) on Mar 30, 2005 at 14:42 UTC
|
perl does have a __BEGIN__ token. You just have to start it with the -x option.
% perl -x
Here there be data.
More of it.
__BEGIN__
#!/usr/bin/perl -wl
use strict; # yeah.
print "Hello, world.";
__END__
^D
Hello, world.
| [reply] [d/l] [select] |
Re: __END__ without __BEGIN__?
by NateTut (Deacon) on Mar 30, 2005 at 18:10 UTC
|
‘Everything that has a beginning, has an end’ | [reply] |