find_chores() is called in scalar context. That scalar context is passed through to the return statement, which places (8,456,310) into scalar context. The Comma Operator in scalar context "evaluates its left argument, throws that value away, then evaluates its right argument and returns that value", in this case 310.
Update: choroba beat me to it ;-)
Update 2: If you want to control the return values of your functions in void, scalar, and list context more precisely than choroba showed, see wantarray:
sub somefunc { my $arg = shift; print "doing something with $arg\n"; return unless defined wantarray; print "doing expensive return value calc\n"; return wantarray ? ('foo','bar') : 'quz'; } somefunc("a"); # just prints "doing something with a" my $x = somefunc("b"); print "$x\n"; # prints "quz" my @y = somefunc("c"); print join(",",@y),"\n"; # prints "foo,bar"
In reply to Re: why the output is not my expected? (updated)
by haukex
in thread why the output is not my expected?
by zhenyisong
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |