On Mon, 2005-03-07 at 14:05, Ben Tilly wrote:
> > 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
Heh, thanks :)
> 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).
I did know it, but forgot, see below.
> > > Here are a few tries from me:
> > >
> > > 1. What is the output of the following, and why?
> > >
> > > package Foo;
> > > our $_;
> > > print grep {$_} -5..5;
> > 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.
Yep, I was. I'd forgotten about your "package Foo" entirely, and didn't
consider that you'd re-pointed $_ to that package using "our". The whole
lexical $_ thing was so fresh in my mind from reading the 5.10 slideshow
this weekend.
Hey wait! This is a problem. "our $_" is supposed to "cancel" lexical
scoping of $_ in 5.10, but that wont work because of what you point out
here! Oops! :)
> "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.
I only vaguely remembered that there was a warning special case. I've
never gone digging into the warning stuff much, I just use it as a
black-box. If I get a warning, fix it. Otherwise, I never think about
it.
> > > 3. Why don't you get a warning from:
> > >
> > > perl -we '"ignore useless use of a constant"'
> 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.
WOW! That's some deep trivia!
> > 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.
In timing tests, I find goto to be slightly slower than named labels,
but much faster than what I would have had to do in File::Copy to
preserve all of the different possible errors (e.g, I don't want the
error produced by the "close", I want the error that caused me to close
in the first place). There are a bunch of permutations and goto was the
only way I found to keep everything I needed, and make it efficient.
Feel free to find a better way!
> 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.)
It's one of the most useful quick-fixes I've ever seen. I use it all the
time!
Thanks, that was fun.
--
Aaron Sherman <[EMAIL PROTECTED]>
Senior Systems Engineer and Toolsmith
"It's the sound of a satellite saying, 'get me down!'" -Shriekback
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm