On 7/29/05, Ingo Blechschmidt <[EMAIL PROTECTED]> wrote:
> Or is @args always readonly and the declaration ([EMAIL PROTECTED] is rw) is 
> an
> error?
The declaration  ([EMAIL PROTECTED] is rw) can't be outlawed as it is how Perl 5
default sig translates to Perl 6.

IMHO @args as a parameter works like a 'my' variable in subroutine
scope. In C<foo> arguments will be copied and (possibly) flattened (as
the parameter is slurpy) and stuffed into @args. In C<bar> it is the
same, but instead of copying, the elements of @args will be aliased to
the actual parameter items. And the point here is "aliased to
parameter ITEMS".

If you change @args with a 'push' or other operation that changes the
array, not its elements, it changes the subroutine variable, as the
connection to @some_array were lost, leaving in the case of bar the
connection to the elements of @some_array.

In conclusion,

         foo @some_array;
         bar @some_array;

are both ok, but changes are not seen from the caller's perpective, as
'push' operated on subroutine parameter @args.

Only

            sub foobar (@args) { push @args, 42 }

would change @some_array in

            foobar @some_array;

That is how I undestood that. Can someone confirm this belief?

Adriano.

Reply via email to