Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: Calling a subroutine from a scalar

by nobull (Friar)
on Jun 30, 2005 at 17:09 UTC ( [id://471394]=note: print w/replies, xml ) Need Help??


in reply to Re: Calling a subroutine from a scalar
in thread Calling a subroutine from a scalar

I have not down-voted your node but I do think the knee-jerk anti-symref response in the case of symbolic CODE references is often inappropriate.

It is perfectly reasonable to use a Perl package as a dispatch table. After all that's excatly what Perl's object implementation does.

Do you think...

FOO->$bar();
...is really any better than...
no strict 'refs'; "FOO::$bar"->();
... when you are not thinking in a OO way?

It should be noted that the security concern often leveled at symbolic CODE refs (that a malicious user could use a qualified name to access a subroutine outside the dispatch table) actually applies in the indirect class method call but does not apply in the explicit symref case.

Replies are listed 'Best First'.
Re^3: Calling a subroutine from a scalar
by blazar (Canon) on Jul 01, 2005 at 09:03 UTC
    I take your point wrt CODE symrefs, and in fact I upvoted your post. OTOH in my experience I fully agree with the widespread consensus that symrefs in general are bad. Not to say that I do not use them myself when I do want to manipulate the symbol table, but that's a whole different story. In most standard situations in which newbies would (naively) like to use symrefs, real refs would only require a moderate amount of more typing, and if you're under strict, actually less, for you have to say no strict 'refs' then. So, all in all, they should be advised against doing so until they are knowledgeable enough to know when it would be the case.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-19 20:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found