Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by tobyink (Canon)
on Mar 02, 2012 at 17:13 UTC ( [id://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.

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://957515]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-19 04:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found