Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^3: How to call a sub-routine ref

by roboticus (Canon)
on Oct 19, 2012 at 20:30 UTC ( #1000037=note: print w/ replies, xml ) Need Help??

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:


To my eye, that stands out better. (But with my luck, it would blow up, so I'd better whip up a test...)

$ cat use strict; use warnings; sub p { print "foo(", join(", ", @_), ")\n"; } my $hr = { key=>\&p }; $$hr{key}->('arg'); $ perl foo(arg)


When your only tool is a hammer, all problems look like your thumb.

Comment on Re^3: How to call a sub-routine ref
Select or Download Code
Re^4: How to call a sub-routine ref
by BillKSmith (Chaplain) on Oct 20, 2012 at 04:00 UTC
    I like the second rule in perlref.
    Anywhere you'd put an identifier (or chain of identifiers) as part of a variable or subroutine name, you can replace the identifier with a BLOCK returning a reference of the correct type.

    Sure, the result is often ugly, but there are no exceptions or special cases. What more could my poor memory want.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1000037]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (16)
As of 2014-09-17 14:46 GMT
Find Nodes?
    Voting Booth?

    How do you remember the number of days in each month?

    Results (85 votes), past polls