awohld has asked for the wisdom of the Perl Monks concerning the following question:

I have the following code:
#!/usr/bin/perl -w use strict; use Data::Dumper; my %items; $items{'joe'} = [ qw(pocket_knife coffee book hanker_chief) ]; $items{'sally'} = [ qw(eye_liner nail_polish purse) ]; $items{'bob'} = [ qw(calculator pocket_protector skittles ) ]; my @remapped_list = map { [ $_ => $items{$_} ]; } keys %items; print Dumper \@remapped_list; @remapped_list = map { [ $_, $items{$_} ]; } keys %items; print Dumper \@remapped_list;
Where I create "@remapped_list" using the comma ( , ) seems natural and I understand its creating an anonymous array of two elements. But how does it work the same with the "=>" ? I thought the => was for creating anonymous hash references.

Can someone explain this, is the "," and "=>" interchangeable when creating lists?

Replies are listed 'Best First'.
Re: List Separator?
by shmem (Chancellor) on Nov 17, 2007 at 22:48 UTC
    The => is called "fat comma", and it is a list operator which forces its left operand (when it is a word) to be a string.

    See perlop.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: List Separator?
by FunkyMonk (Chancellor) on Nov 17, 2007 at 22:46 UTC
    They're almost the same. =>, the "fat comma", will quote the word to its left. That's the only difference between => and a comma.