Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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.

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).


    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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://957515]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2018-01-23 14:23 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (247 votes). Check out past polls.