in reply to Re^2: How to call a sub-routine ref
in thread How to call a sub-routine ref
Odd, I find your examples a good case for using the second one. Again, different people will find different things more clear.
When I use hashes, I generally use $$h{foo} in preference to $h->{foo}, primarily because it's easier to type, and I use hashes quite a bit. If I were trying to make it visually distinctive, I'd make the harder to type one be for the less frequently used case. Thus, I'd use something like:
$$hashref{key}->('arg');
To my eye, that stands out better. (But with my luck, it would blow up, so I'd better whip up a test...)
$ cat t.pl use strict; use warnings; sub p { print "foo(", join(", ", @_), ")\n"; } my $hr = { key=>\&p }; $$hr{key}->('arg'); $ perl t.pl foo(arg)
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: How to call a sub-routine ref
by BillKSmith (Monsignor) on Oct 20, 2012 at 04:00 UTC |
In Section
Seekers of Perl Wisdom