View Single Post
  #5   (View Single Post)  
Old 15th November 2011
ocicat ocicat is offline
Administrator
 
Join Date: Apr 2008
Posts: 3,319
Default

Quote:
Originally Posted by Carpetsmoker View Post
One more piece of good(-ish) news is that you can now use:
$var = fun()['2'];

This is probably something of a quick syntax hack, and certainly not the same "everything's an object" model Python or Ruby sport, but it saves a line of typing.

I wonder if it allows:
$vars = fun()['2']['4'];
or
$vars = fun2(fun()['2'])['3'];
Similar syntatic sugar has been in Perl since dirt was formed. In fact, I have been asked variants of this question in job interviews just to gauge much experience I had with the language. For example, if constructing today's date is the desired purpose:
Code:
#!/bin/env perl
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
printf "%d-$mon-$mday\n", $year + 1900;
...can be reduced to the following which eliminates a lot of extraneous clutter:
Code:
#!/bin/env perl
my ($year, $mon, $mday) = (localtime time)[5,4,3];
printf "%d-$mon-$mday\n", $year + 1900;
FWIW.
Reply With Quote