scissor syntax
This is one of the things that I always have trouble remembering in Perl. Occasionally (when it’s late, I’m tired and just want to finish up and go sleep), I am tempted to write hackish code like this:
Connect to database
Get a statement handle out$statement_handle->fetchrow_array()[0];
Which works sorta ok, till you try to print the result of that fetchrow_array call; and then everything goes bad in a hurry. Annoying, but I hadn’t bothered figuring out how I could work around it… Till today. Popped into #perl on freenode. I was pointed to the fine manual which includes a section on symbolic unary operators.
So, what I really need is a leading unary + to disambiguate. Cor. All this time programming Perl and I never needed something like that. So, what I need to say is:
print +($statement_handle->fetchrow_array())[0];
Sounds trivial, but it took a similar epiphany for the delights of map to be revealed a while ago. Learn something new, most days.
And I’m listening to Ta Dah by the Scissor Sisters and liking it. Muchly, in fact.
Just say it
Can't post a comment ? Any other commenting problems ? email lair - at - fierydragon . org