Hey folks,

Executive summary:  It looks like, no matter what context foo() is called
in, its arguments are always evaluated in list context.  Is this correct?
I had always understood that:
        - a function's arguments were evaluated in the same context as the
context of the function (hmm...actually, thinking about it, this seems
like it can't be right.  Is it simply always LIST, or can it vary?)

        - a function's context propogated downwards into any functions it
calls.



Full version:

I thought I had a pretty good handle on the whole concept of context, but
I've tripped over it several times recently, so I set up a test:


#!/usr/local/bin/perl -w

use strict;

$\ = "\n";

{print "\$x = bar()";  my $x =  bar();  foo($x);}
{print "\@x = bar()";  my @x =  bar();  foo(@x);}

{print "\$x = foo( bar() )";  my $x =  foo( bar() );}
{print "\@x = foo( bar() )";  my @x =  foo( bar() );}
{print "foo( bar() )";                 foo( bar() );}

sub foo {
    while (@_) {
        my $parm = shift;
        for ($parm) {
            unless (defined) { $parm = 'VOID';  last; }
            $parm = $parm ? 'LIST' : 'SCALAR';
        }
        print "\t$parm";
    }
}

sub bar { return wantarray(); }
print "Done.";
__END__


This outputs what context bar() is called in.  I expected this to output
the following:

########### EXPECTED OUTPUT.  THIS IS NOT WHAT IT GIVES
$x = bar()
    SCALAR
@x = bar()
    LIST
$x = foo( bar() )
    SCALAR
@x = foo( bar() )
    LIST
foo( bar() )
    VOID
Done.
########### /EXPECTED OUTPUT.



Instead, I get this:


$x = bar()
    SCALAR
@x = bar()
    LIST
$x = foo( bar() )
    LIST
@x = foo( bar() )
    LIST
foo( bar() )
    LIST
Done.


Any comments, anyone?


Dave





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to