in reply to Re: defined &{ $pkg . '::foo' } vs. $pkg->can( 'foo' )
in thread defined &{ $pkg . '::foo' } vs. $pkg->can( 'foo' )
Case in point:
This prints "new" on the first line, and "new, foo" on the second. I changed the defined() test a bit, because with $pkg in there, it's saying "of the symbols in $pkg, which are defined as functions in this current package I'm in?" rather than "... which are defined as functions in $pkg?".package Parent; sub foo { 1 } package Child; @ISA = 'Parent'; sub new { bless {}, shift } $foo = 10; package main; my $pkg = "Child"; print join(", ", grep defined &{ $pkg . "::$_" }, keys %{ $pkg . '::' +}), "\n"; print join(", ", grep $pkg->can( $_ ), keys %{ $pkg . '::' }), "\n";
|
|---|