Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Why this simple code doesn't work?

by tobyink (Abbot)
on Mar 02, 2012 at 17:13 UTC ( #957515=note: print w/ replies, xml ) Need Help??


in reply to Re: Why this simple code doesn't work?
in thread Why this simple code doesn't work?

Don't call your subroutines with a prepended "&".

Actually in this case the "&" is meaningful. There is a Perl built-in called read, so the "&" serves as disambiguation, proving that you want to call the sub, and not the built-in.

Of course, the wisdom of defining a function with the same name as a Perl built-in is debatable. Sometimes it makes sense (e.g. each in Set::Scalar is designed to be used as a method, so never looks ambiguous in code. Naming it same as the built-in serves as a hint as to its purpose.) but I'm not sure this is one of those times.


Comment on Re^2: Why this simple code doesn't work?
Select or Download Code
Re^3: Why this simple code doesn't work?
by CountZero (Bishop) on Mar 02, 2012 at 17:44 UTC
    In this case it is not meaningful to recycle a built-in keyword and even far less meaningful to add a totally wrong prototype (and then call the sub without regard to prototypes).

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2014-10-25 08:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (142 votes), past polls