Can't seem to wrap my head around perl6 lists.

They're not arrays. They seem to exist almost as literals.
When I assign a list to an array, it stops acting like a literal list.

This works as expected:
for 1,2,3,4 {say "here is $^first";}
here is 1
here is 2
here is 3
here is 4

THis does not work as expected:
my $otherlist = (11,22,33,44);
for $otherlist {say "here is $^first";}
here is 11 22 33 44;

Calling "flat" on the scalar doesn't change the output.
The only thing that seems to get it to do the right thing is to put "@" in
front of the scalar containing the list.

for @$otherlist {say "here is $^first";}
here is 11
here is 22
here is 33
here is 44

so, I can make a literal list 1,2,3 and loop on it,
and I can loop on an array,
but I can't loop on a scalar with a list in it
and I can't flatten a list inside a scalar.

Is there a rule underlying this behavior that makes it consistent?
Because right now, it seems like a couple of arbitrary rules
enforced to get a particular, but inconsistent, behavior.

Greg




_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to