Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: Why no warnings for 1 in void context?

by jdporter (Canon)
on Jul 16, 2005 at 20:49 UTC ( #475504=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Why no warnings for 1 in void context?
in thread Why no warnings for 1 in void context?

Very good! Yes, it's a little known feature of perl that certain nroff directives are legal in perl, in the sense that they are always recognized, even if not defined. (They will not override or change the meaning of any actual definitions in your code.) The place to begin is in op.c, in function Perl_scalarvoid. Here we learn that any symbol occurring in void context which begins with 'di', 'ds', or 'ig' is given a pass to sail by without warning.

(In the exact same place, 0 and 1 are defined as non-warning-worthy in void context. merlyn knew that, of course.)

The code tells us to look in the pink camel [that's Programming Perl 1st ed.], near page 319. This is where two scripts, wrapman and wrapinst, are presented. This is really the best clue to why these nroff directives are special... and what it boils down to is Larry's (clever) attempt to make it easy to document code by making it possible for (some) code to be both legal perl and legal nroff. I think even he would admit that it wasn't terribly successful. But this was in the days before POD.

No doubt this feature has been exploited in obfu.


Comment on Re^3: Why no warnings for 1 in void context?
Re^4: Why no warnings for 1 in void context?
by Anonymous Monk on Jul 16, 2005 at 21:42 UTC

    Why not just quote the source?

    // op.c 765 else if (SvPOK(sv)) { /* perl4's way of mixing documentation and code (before the invention of POD) was based a trick to mix nroff and perl code. The trick was built upon these three nroff macros being used in void context. The pink camel has the details in the script wrapman near page 319. */ if (strnEQ(SvPVX(sv), "di", 2) || strnEQ(SvPVX(sv), "ds", 2) || strnEQ(SvPVX(sv), "ig", 2)) useless = 0; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (13)
As of 2014-09-23 14:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (223 votes), past polls