in reply to Re: Entry Widget - validatecommand
in thread Entry Widget - validatecommand

sub print { print $value unless $value eq '-'; }
...

Incidentally, why does this  print sub [not] simply call itself recursively??

Its a namespace problem (feature? artifact?). Your new  print is defined in  main and the built-in  print is defined in  CORE and the  CORE namespace has search precedence. Try the following:

>perl -wMstrict -le "sub print { CORE::print('foo') } ::print; " foo >perl -wMstrict -le "sub print { ::print('foo') } ::print; " Deep recursion on subroutine "main::print" at -e line 1. Terminating on signal SIGINT(2)

Replies are listed 'Best First'.
Re^3: Entry Widget - validatecommand
by Athanasius (Archbishop) on Jul 24, 2012 at 08:47 UTC

    Thanks, AnomalousMonk, for the explanation. Your statement:

    the CORE namespace has search precedence.

    raises a new question: How, then, does the original code ever find the print sub defined in namespace main if the sub isn’t explicitly qualified with its namespace (i.e., main::print)? Why doesn’t Perl always find CORE::print?

    I think I found the answer: the original code works only because it uses a reference to the sub:

    -command=> \&print

    and in this case the reference is disambiguated using lexical scope. I found an explanation of the latter in the Camel Book, 4th Edition, “Name Lookups,” pages 62–65. Is there any documentation on how Perl looks up subroutine names when a subroutine is actually called (as opposed to being referenced)?

    Thanks,

    Athanasius <°(((><contra mundum