chen li wrote:

    Let's look at the calls:

: my $call=&Bar::print_result(1,2);
: my $call2=Bar->print_result(2);

    $call gets whatever is returned by Bar::print_result().
As we see below, Bar::print_result() always returns 1.


    Now. we'll look at what the sub returns:

: sub print_result{
:     my $data1=shift;
:     my $data2=shift;
:     print "This is the data1 $data1 and data2 $data2", "\n";
:  }

    Unless the return() statement is used, a sub routine
returns the value of the last operation or assignment. This
subroutine returns the success of the print. If the print is
successful, this subroutine, whether called as a method or as
a subroutine, will always return 1.

    Since $call will always be set to 1, we have confirmation
that the call to both the subroutine and the method were
successful.


: My question: What does it mean? Does it mean
: successfully calling either a subroutine or method?


: This is the data1 1 and data2 2

    @_ = (1, 2)

: $VAR1 = 1;

    Sub routine call was successful.

: This is the data1 Bar and data2 2

    @_ = ('Bar', 2)

: $VAR1 = 1;

    Sub routine call was successful.


    This may be a more useful test.

use strict;
use warnings;
use Bar;

print "Sub routine call:\n\tBar::print_result(1,2);\n";
my $call = Bar::print_result(1,2);


print "\n\nMethod call:\n\tBar->print_result(1,2);\n";
$call = Bar->print_result(1,2);

__END__

package Bar;

use strict;
use warnings;
use Data::Dumper 'Dumper';

sub print_result{
    print Dumper [EMAIL PROTECTED];
}

1;



HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
Free Market Advocate
Web Programmer

254 968-8328

Don't tread on my bandwidth. Trim your posts.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to