On Mon, 07 Mar 2005 13:24:31 -0500, Aaron Sherman <[EMAIL PROTECTED]> wrote:
> On Mon, 2005-03-07 at 12:56, Ben Tilly wrote:
> > On Mon, 07 Mar 2005 08:36:56 -0500, Aaron Sherman <[EMAIL PROTECTED]> wrote:
> > > On Mon, 2005-03-07 at 01:51 -0500, James Freeman wrote:
> > >
> > >  [...] If you know more trivia
> > > than I do (I've yet to see that), then I would hire you on the spot.
> >
> > Let's turn this into, "Let's try to stump Aaron!"
> 
> Heehee! I mis-spoke. I meant "I've yet to see that in an interview." I
> have seen plenty of people on this list or the various p6x lists that
> make me look like a newbie. I was in no way trying to claim to be the
> ultimate Perl trivia expert.

Ah, and you gave me such hope. :-P

Spoilers below.  I'd give you 2/5, being slightly generous on
question 2 (you didn't really say why it is special, but I can
believe that you know it).

> > Here are a few tries from me:
> >
> > 1. What is the output of the following, and why?
> >
> >   package Foo;
> >   our $_;
> >   print grep {$_} -5..5;
> 
> Well, assuming you don't want me to test that on the command-line, I'm
> not sure that the answer is the same across all of the commonly used
> versions today. In 5.6.1... I'm guessing an error about using our on $_.
> In 5.10 (upcoming), I know "our $_" is supposed to be a "go back to the
> global $_, not my lexical version", but we don't have lexical $_ in
> 5.8.x yet, so I'm not sure what it would do there. Quite possibly, it
> would be ignored, in which case you would get -5 through 5 being printed
> without 0, of course.
> 
> This seems like less of a "Perl trivia" question and more of a "state of
> Perl development" question. Not invalid, just pointing that out.

Actually it is Perl trivia, though I must say that I don't happen to know
how Perl 5.10's lexical $_ might affect this.  (I suspect that it won't.)

> Ok, having written the above, I went and checked it out. It prints
> nothing under all versions I have access to. Wish I had time to figure
> out why. I'm sure it has to do with the interaction of our and closures,
> but I have no clue.

Nope, you're on the wrong track.

$_ is normally always $main::_.  The our declaration forces $_ to be
$Foo::_, so you don't see $main::_ which is being set by grep.  This
is why it is important to NEVER set $_ without localizing it implicitly
or explicitly, you could really cause problems for someone several
callers back who'se using a map or grep!

> > 2. Explain what's special about "0 but true" and why
> > that's never actually needed.
> 
> Erg... "0 but true" is true by virtue of not being one of the special
> cases that are considered false (e.g. "0")... and why is it never
> needed? I thought it was, so I'm guessing that a recent version added
> some sort of replacement? You can, of course, use "0.00" or construct an
> SV that has numeric value 0 and string value "false".
> 
> Am I missing something?

"0 but true" is special cased to not generate a warning upon
numerical conversion.  As you note, "0.00" is also a true value
that evaluates to 0 and doesn't need a special case to work.

> > 3. Why don't you get a warning from:
> >
> >   perl -we '"ignore useless use of a constant"'
> 
> It's not in a void context, so it's being used. I'm not too familiar
> with the warning you're expecting, as I don't usually run into it, but,
> as the last statement in a block, this value is used... Perl would have
> a hard time telling that the value of the block isn't used....

Perl has no problem figuring out whether to generate the
warning and will do so for:

  perl -we '"a random string here"'

The answer is that the "ig" at the start of the string trips a special
case going back to Perl 4 to allow people to include a troff
formatted man-page inside their Perl program.  This was a
predecessor to Perl 5's POD.

> > 4. As Larry points out in perlsyn, he has never felt the need
> > to use goto LABEL in Perl.  (With good reason, as was first
> > proven in the 70's, any algorithm that can be written with
> > goto can be written, with the same efficiency, with named
> > loop control.)  Why, then, did he include the feature?
> 
> Goto is commonly used in generated code which would be much more
> difficult to generate using named loop controls (e.g.
> Parse::RecDescent).

Exactly right!  In particular writing s2p becomes a lot easier if
Perl has goto LABEL.  You can then translate goto to goto.

> However, as someone who has contributed code to the core which is still
> in use, and which uses goto in this way (grep goto in File/Copy.pm), I
> can say that there are times when you really want goto, because the
> alternative is ugly as sin or slow or loses information or a combination
> of the above.

Given how goto scans for its target to jump to, goto is likely to be
very slow in Perl.

> Named loop controls + efficient exception handling solves for all of the
> above, and Perl 6 will no longer need that goto in File::Copy for that
> very reason (though File::Copy probably won't be written in Perl 6, but
> in PIR or C).
> 
> > 5. Who made the syntax $somesub->() work, and why?
> 
> Oh now that's just social trivia. I have no idea who made what patches
> to the core and why. I have to much to do. Speaking of which ... have a
> nice day!

Yup, I was trying to find something that virtually nobody could
answer.

The answer is Randal Schwartz, to win a bar bet on how late in a
release cycle he could get a syntax change into Perl.  IIRC he got
it into Perl 5.004 between the final release candidate and the
actual release.  (I may be misremembering the details though.)

Cheers,
Ben
 
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to