Hi All,

Thinking back, my real question should have been:
is AUTOLOAD is invoked/declared before real time ?
Thanks
Chanan

On Thu, Jul 15, 2010 at 10:13 AM, Chanan Berler <[email protected]> wrote:
> Hi All,
>
> Me going back on working with perl made me go over and look at the books.
> Got a question for you all:
>
> when invoking a none declared subroutine, I was told it will invoke
> the AUTOLOAD sub with same arguments
> sent to my origin (none declared) sub.
>
> So I wrote the following:
> and the output was:
> Before:
> AUTOLOAD  | *TestMe::AUTOLOAD
> funny     | *TestMe::funny
> single    | *TestMe::single
> Found: 12
> Running funny from Autoload
> Before:
> AUTOLOAD  | *TestMe::AUTOLOAD
> funny     | *TestMe::funny
> single    | *TestMe::single
>
> Q: why am I seeing the funny sub before declaring it ? should I not
> see it after invoking the sub ?
>
>
> Here is what I wrote:
> ==================
> #!C:\Perl\bin\perl.exe
> use warnings;
> use strict;
>
> package TestMe;
> our $single = 1;
> sub AUTOLOAD
> {
>   sub funny{
>       my $arg = shift;
>
>           print "Found: $arg\n";
>       if ($single)
>           {
>          print "Running funny from Autoload\n";
>                  $single--;
>           } else {
>
>                 print "Running the sub after declaring.\n";
>           }
>
>   }
> }
>
> print "Before:\n";
> &::dispSymbols(\%TestMe::);
> &funny(12);
> print "Before:\n";
> &::dispSymbols(\%TestMe::);
>
>
> sub ::dispSymbols {
>    my($hashRef) = @_;
>    my(%symbols);
>    my(@symbols);
>
>    %symbols = %{$hashRef};
>   �...@symbols = sort(keys(%symbols));
>
>    foreach (@symbols)
>        {
>        printf("%-10.10s| %s\n", $_, $symbols{$_});
>    }
> }
>
> --
> ===================
> ----     Chanan Berler    ----
> ===================
>



-- 
===================
----     Chanan Berler    ----
===================
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl

Reply via email to