in reply to Return values from package methods

I tried
#!/usr/bin/perl use Data::Dumper; my $test = Test->new; my $a = $test->test; my $b = \$test->test; print Dumper( $test->test ); print Dumper( $a ); print Dumper( $b ); exit 0; package Test; use strict; sub new { return bless {}, shift; } sub test { } 1; __END__
That gives me on 5.6.1
$VAR1 = bless( {}, 'Test' ); $VAR1 = undef; $VAR1 = \bless( {}, 'Test' );
Looks rather strange to me.

Replies are listed 'Best First'.
Re: Re: Return values from package methods
by dragonchild (Archbishop) on Aug 19, 2003 at 13:13 UTC
    In 5.6.0 on AIX, I did:
    #!/usr/bin/perl use Data::Dumper; my $test = Test->new; $test->xyz; my $a = $test->test(1); my $b = \$test->test(2); print Dumper( $test->test(3) ); print Dumper( $a ); print Dumper( $b ); exit 0; package Test; use strict; sub new { return bless {}, shift; } sub xyz { (1..3) } sub test { } 1; __END__ ----- $VAR1 = bless( {}, 'Test' ); $VAR2 = 3; $VAR1 = undef; $VAR1 = \2;

    It looks like the implicit return in list context, barring no other statements, is @_. Having an intervening statement didn't do anything.

    ------
    We are the carpenters and bricklayers of the Information Age.

    The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.