[tpm] Lightning Talk lineup
Dave Doyle
dave.s.doyle at gmail.com
Fri Oct 3 10:31:21 PDT 2008
On Fri, Oct 3, 2008 at 12:39 PM, Alex Beamish <talexb at gmail.com> wrote:
> Amazingly enough, I actually used this new-found piece of knowledge
> today, building an array of hashrefs for a call to a library that I
> cannot (yet) change:
>
> my @symbols = map { +{ 'key' => $_ } } @things;
>
> Proof once again that Perl is an unbelievably powerful language. I'm
> glad you used it, and I asked you about it. :)
>
I'm glad I used it too! Glad I can keep getting employment in Perl! I've
always found these little things fun. There's apparently a whole thread of
these little "Hidden Features of Perl" on StackOverflow right now:
http://stackoverflow.com/questions/161872/hidden-features-of-perl
Going back, when I was interviewing for my current job with Richard, he took
me out on a technical interview before I got to meet the VP ('cause if I
did, I found out when the VP chatted with me, it meant I was worth actually
talking to).
Anyhow, Richard asked me this question on the interview. Let's suppose
you've got an OO module. Now, for some reason, you want an 'a' method that
is really an alias for 'b'. Your assignment? Do this in the least number of
characters possible without shifting the args off of @_.
Now, I thought I was being smart with:
sub a {
$_[0]->b(@_[1..$#_]);
}
But I'd forgotten that I didn't need the ';' because it's the last statement
in the block. Stupidly, I'd forgotten that invoking with -> just stuffed
the invoking blessed ref into the arg list so I could have done this:
sub a {
b(@_)
}
But then Richard broke my head with:
sub a {
&b
}
My jaw literally hit the table. I'd also not know the & invocation style
(without brackets) automatically passed @_ into the sub. I'd thought that &
is soooo Perl 4 and beneath my notice. Whoops. Two characters. Two bloody
characters to my 21.
Got the job though. :)
--
dave.s.doyle at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20081003/d692b9b6/attachment.html>
More information about the toronto-pm
mailing list