Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: 'Ambiguous call' diagnosis seems ambiguous

by chromatic (Archbishop)
on Aug 03, 2012 at 00:56 UTC ( #985133=note: print w/replies, xml ) Need Help??

in reply to 'Ambiguous call' diagnosis seems ambiguous

Perl's tokenizer classifies some keywords as "weak keywords" such that you can override them with user-defined functions. (Calling them is another matter.) delete is a weak keyword and each is not. our is weak, but sub is not:

use strict; use warnings; sub each { warn 'main::each() was called' } sub delete { warn 'main::delete() was called' } sub dump { warn 'main::dump() was called' } sub chop { warn 'main::chop() was called' } sub our { warn 'main::our() was called' } my %person = ( name => 'Ken Takakura' ); while ( my ($key, $val) = each %person ) { print "$key: $val\n"; } &our( $person{name} ); delete $person{name}; chop $person{name}; dump( $person{name} );

I don't know how to make a list of weak and normal keywords without reading the source code (keywords.c or regen/

Replies are listed 'Best First'.
Re^2: 'Ambiguous call' diagnosis seems ambiguous
by anazawa (Scribe) on Aug 03, 2012 at 01:45 UTC
    Thanks for your suggestion. Your code output the following:
    Ambiguous call resolved as CORE::each(), qualify as such or use & at a line 12. Ambiguous call resolved as CORE::chop(), qualify as such or use & at a line 18. dump() better written as CORE::dump() at line 19. Ambiguous call resolved as CORE::dump(), qualify as such or use & at a line 19. name: Ken Takakura main::our() was called at line 8. Use of uninitialized value $person{"name"} in scalar chop at ambiguous line 18. Abort

    This result shows us that delete and our belong to "weak keywords", and each, chop and dump don't.

    The following was quoted from regen/

    145: -chop 160: +delete 163: -dump 164: -each 261: +our

    Plus (+) signs maybe mean "weak".

    Your comment meant a lot to me :)

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2018-06-18 23:40 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (111 votes). Check out past polls.