In the last 6 months I have come to feel that understanding Perl
contexts is the most important and difficult thing in the language, so
your statement and question very important....
> I don't see the point of the subroutine. If
> you want to return a hash from a subroutine,
> use 'return'. Note that foo() actually returns
> a list (or is it an array?). We decide to stuff
> the result into a hash.
>
It returns a "list" because of exactly what you said in your last
sentence, "We decide to stuff the result...", so it is a list until you
have decided what to stuff it into, which could be a
'list' of scalars
($scalara, $scalarb) = foo();
array slice
@array[ 3 .. 4] = foo();
hash slice
@hash{ 'key1', 'key2' } = foo();
arguments to a loop
foreach ( foo() );
arguments to another sub
bar( foo() );
or just an 'array'
@array = foo();
etc.
A square is a rectangle, but a rectangle is not necessarily a square.
An array is a list, but a list is not necessarily an array.
http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>