in reply to Redundant function calls in constructor?
You can use slicing to eliminate the redundant calls:
$ cat foo.pl use strict; use warnings; use Data::Dump 'dump'; my %h; @h{'A', 'B', 'C'} = @{foo()}[0,1,2]; print dump(\%h); sub foo { [3, 2, 1]; } $ perl foo.pl { A => 3, B => 2, C => 1 }
The @h{'A', 'B', 'C'} is a hash slice, and the right uses an array slice. You'll find hash and array slicing described in perldoc perldata.
Update: Fixed link to docs.
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|