Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Ambiguous calls

by choroba (Abbot)
on Aug 03, 2012 at 00:41 UTC ( #985131=note: print w/ replies, xml ) Need Help??


in reply to 'Ambiguous call' diagnosis seems ambiguous

The warning comes during the compilation phase (try adding a BEGIN block at the end of the programme). I guess it is because each is special - Perl must create an iterator for it (if it is the CORE:: one). Maybe the internals experts will tell us more.


Comment on Re: Ambiguous calls
Re^2: Ambiguous calls
by anazawa (Scribe) on Aug 03, 2012 at 01:27 UTC
    Thanks for your suggestion. I agree with you that each is special. According to chromatic's explanation, delete belongs to "weak keywords', and each doesn't. By the way, I'm not sure how to add a BEGIN block to my code. Would you please attach your code?

      I think choroba’s point is that you can use BEGIN blocks to determine when the warning is issued. For example:

      #! perl use strict; use warnings; BEGIN { print "BEGIN 1\n"; } sub each { warn 'main::each() was called' } BEGIN { print "BEGIN 2\n"; } sub delete { warn 'main::delete() was called' } BEGIN { print "BEGIN 3\n"; } my %person = (name => 'Ken Takakura'); while (my ($key, $val) = each %person) { print "$key: $val\n"; } delete $person{name}; BEGIN { print "BEGIN 4\n"; }

      produces this output:

      BEGIN 1 BEGIN 2 BEGIN 3 Ambiguous call resolved as CORE::each(), qualify as such or use & at 1 +66_SoPW.pl line 13. BEGIN 4 name: Ken Takakura

      which shows that the warning is issued during the compile phase (before the main code is executed) at the point where the code specifies an ambiguous call to each.

      This works because BEGIN blocks are executed during compilation, as soon as they are seen by the Perl compiler, before the main code is run. See BEGIN, UNITCHECK, CHECK, INIT and END.

      HTH,

      Athanasius <°(((><contra mundum

        Thanks for your explanation. That makes sense. If I added a BEGIN block to the end of my code, 'Ambiguous call' warning would appear before the block was executed, right? Your code shows that warnings pragma complains about each %person at the compile phase. Thanks a lot :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2014-12-21 09:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (104 votes), past polls