Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: new keyword "size" to avoid scalar trap ? ( scalar @array != scalar(LIST) )

by roboticus (Chancellor)
on Dec 07, 2012 at 17:05 UTC ( #1007796=note: print w/ replies, xml ) Need Help??


in reply to new keyword "size" to avoid scalar trap ? ( scalar @array != scalar(LIST) )

LanX:

With the scalar operator and arrays evaluating to their length in scalar contect, I don't see a need for it. But if someone decided to change perl to do something like this, I'd rather see them overload length to accept a hash, array or reference to a hash or array.

...roboticus

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


Comment on Re: new keyword "size" to avoid scalar trap ? ( scalar @array != scalar(LIST) )
Replies are listed 'Best First'.
Re^2: new keyword "size" to avoid scalar trap ? ( scalar @array != scalar(LIST) )
by LanX (Canon) on Dec 07, 2012 at 17:22 UTC
    > I don't see a need for it.

    Honestly, did you immediately spot the problem in BUK's code?

    Re: Idiom to return 0 or random number of array elements

    UPDATE:

    Do you really prefer explaining goatse "op"  =()= and turtle "op" @{[ ]} to newbes who simply need to count the elements a function returns?

    UPDATE:

    > I'd rather see them overload length to accept a hash, array or reference to a hash or array.

    Then it's quite impossible to tell what length ($str) is supposed to return. 1 for the list-size or the char-size of $str?

    Cheers Rolf

      LanX:

      No, I didn't notice the error. And I've never used goatse, turtle or kite. Perhaps if I had, I'd see the need for it.

      As far as the practicality of what length $str is supposed to return, I didn't give it much thought. I was just expressing my color preference for new new shed out back. ;^)

      ...roboticus

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (15)
As of 2015-07-30 17:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls