Ben said:
Absolutely not. my %h = map { $_ => 1 } qw/a b c/; is quite a common
idiom.
Well, you're still getting that many *sets* which is probably what I
should of said, or have been clearer. In that example, you get 3 set of
hash pairs resulting from the 3 element list. The point is you get
count_of_passed_list amount of something from the map, in some form or
another. How exactly it's returned is determined by the template inside
the map.
No, you're misunderstanding the difference between a list and an
array. Evaluating an array in list context returns a list of its
elements *as they are now*;
I seem to understand it just fine. What we both said above seems to be
true. Maybe we're just misunderstanding what the other is trying to say?
under most circumstances, it returns a
list of aliases to those elements, but any changes to the order of
the elements in @ary are not propagated into the list. Consider
my @ary = qw/a b c/;
sub foo {
my @keep = map "$_", @_; # kill the aliasing
Ok @keep now contains (a, b, c)...
@ary, which comes from a scope outside this sub, now contains (h, a, b,
c)
$_[$_] .= $keep[$_] for 0..$#_;
Keep in mind $_[0] *still* points to what used to be the first element
of @ary. Remember, the aliasing isn't to the *array* but to it's
*elements*. This is because when you normally pass args to a sub (e.g.,
do_something($x, $y); ), the aliasing is with $x and $y to $_[0] and
$_[1]. Passing an array just like passing that many scalars as are
elements in the array; each individual one gets aliased to the next
sequential element of @_ in the sub's scope.
}
foo @ary;
print for @ary;
Running this (with the last line as `print "$_\n" for @ary;` for
clarity) prints:
h
aa
bb
cc
Seems the changes propgated just fine to me. You pushed 'h' to the
beginning of @ary, then you effectively iterated from
$ary[1]..$ary[$#ary].
Map is the same way in that regard; $_ is an alias to an *element*
It separates for (LIST) from everything else that accepts a LIST.
This is why I called it 'weird'.
I still don't see what you consider weird about it. What does it do that
you don't expect it to do?