in reply to Syntax for casting map to a hash or an array
The outer pair of curlies with the sigil dereferences the anonymous hash created by the inner pair, acting on the list returned by the block in the innermost pair, which is the argument to map. keys wants a hash.
Also, Edit: Also, you likened "array" to:
This is a scalar holding a reference to an anonymous array. An array is differentiated from a list by context, not by square versus round brackets.$VAR1 = [ 'one', 'fish', 'two', 'fish', 'red', 'fish', 'blue', 'fish' ];
But for your last question, if you want an array containing the flattened hash derived from your map and then want to dumper it to get the output you showed:
Because square brackets return a reference to what map returns, so Data::Dumper prints as one data structure.say Dumper( [ map { $_ => "fish" } qw(one two red blue) ] );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Syntax for casting map to a hash or an array
by cbeckley (Curate) on Apr 05, 2017 at 15:40 UTC | |
by stevieb (Canon) on Apr 05, 2017 at 15:48 UTC | |
by cbeckley (Curate) on Apr 05, 2017 at 16:09 UTC | |
by stevieb (Canon) on Apr 05, 2017 at 18:24 UTC | |
by cbeckley (Curate) on Apr 05, 2017 at 18:50 UTC | |
| |
by haukex (Archbishop) on Apr 05, 2017 at 16:08 UTC | |
by cbeckley (Curate) on Apr 05, 2017 at 16:37 UTC | |
by 1nickt (Canon) on Apr 05, 2017 at 16:09 UTC |