__END__ comment confusing in man-page-in-perl-script 
Author Message
 __END__ comment confusing in man-page-in-perl-script

Deciding that it was time that I had my cake and ate it, I set out to
see if I could have a perl program with an embedded man page AND
embedded data (using __END__ and the <DATA> filehandle).  Well, yes, I
can -- but the current examples of self-documenting programs, such as
ex/rename  in the perl 4.035 distribution, are (even?) more obfuscated
than they need to be, and suggest that the job is more difficult than
in fact it is.

Consider the following (not shar-ed so that you can run this mail with
perl -x):

#!/usr/local/bin/perl
'di';
'ig00';
# faker -- demonstrate that the __END__ in self-documenting
#          perl template is ignored
##############################################################################

while (<DATA>)
{
        print;

Quote:
}

        # These next few lines are legal in both Perl and nroff.

.00;                    # finish .ig

'di                     \" finish diversion--previous line must be blank
.nr nl 0-1              \" fake up transition to first page again
.nr % 0                 \" start at page 1
';<<'.ex'; #__END__ ############# From here on it's a standard manual page ############
.TH RENAME 1 "5 October, 1992"
.AT 3
.SH NAME
faker \- come to a spurious __END__
.SH SYNOPSIS
.B faker
.SH DESCRIPTION
.I Faker
.SH AUTHOR
Dominic Dunlop
.SH "SEE ALSO"
.IR "The Camel Book" ,
chapter 6.
.SH BUGS
Probably manifold
.ex
__END__
And this is where the story really begins...

The __END__ in the line ``From here on it's...'' is part of a comment,
and so is not seen by perl's tokener.  I suspect it's there because,
in a previous incarnation of the hack (see camel book, page 315 ff),
it was not in a comment, and was really needed.  It certainly threw
me, as I remembered the camel book saying that the trick was carried
off by making perl see the man page as data.  In fact, it currently
sees it as a here document{*filter*} off a null statement.  The second
__END__ in  faker  is outside a comment, is seen by the tokener, and
does flag the start of stuff one can read via <DATA>.  Wheee!
--
Dominic Dunlop



Sat, 25 Mar 1995 01:00:53 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Man pages or Man page for TK widgets

2. sh, man page, and perl in one script!

3. Wanted: c source to man page script(s)

4. tk man, perl man, and man servers

5. Confused - pod and man files

6. perl man page for DOS (big-perl)

7. Perl Man Pages on BSD

8. WWW Perl man page (html files)

9. new in perl, diffcult man page, any suggestions?

10. Hypertext Perl Man Page from CMU

11. Perl example in Net::FTP man page

12. REPOST: FIXES to perl/makewhatis (core dump on OW3 man pages)

 

 
Powered by phpBB® Forum Software