Skip to content

Commit

Permalink
Tweak the documentation of as_hash()
Browse files Browse the repository at this point in the history
* Consistent use of my (as required by perl5i)

* Consistent use of spacing in map blocks

* Be a little more cagey about exactly what the value will be.
  This will let us change it in the future if necessary.

* Show a real world example of use

For #172
  • Loading branch information
schwern committed Nov 23, 2011
1 parent fd036bc commit 8202f2c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/perl5i.pm
Expand Up @@ -622,17 +622,18 @@ If @array is not a multiple of the iteration (for example, @array has
=head3 as_hash
%hash = @array->as_hash;
my %hash = @array->as_hash;
This method returns an array with the original elements of @array mapped to 1.
Its functionality is the exact same as:
This method returns a %hash where each element of @array is a key.
The values are all true. Its functionality is similar to:
%hash = map{ $_ => 1 } @array;
my %hash = map { $_ => 1 } @array;
Example usage:
my @array = ("a", "b", "c");
my %hash = @array->as_hash;
my @array = ("a", "b", "c");
my %hash = @array->as_hash;
say q[@array contains 'a'] if $hash{"a"};
=head3 diff
Expand Down

0 comments on commit 8202f2c

Please sign in to comment.