New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Method to turn an array into a hash #172
Comments
I think that is too ambuguous. Most perl peopel know that %thing = @thing works to turn an array of key, value pairs into a list. Many might see this method and just assume it is that and think it is pointless. Even more concerning is that some people not as familiar with perl might think it does that not realising it is so easy on it's own. Truth be told %things = @things sounds to me like an @Array->as_hash too. perhaps: @Array->as_hash_keys( $value ) |
@jarich, please re-read my comment in detail. I know the 2 things are different, that was my whole point. The point was that the name could resonably apply to either and is thus ambiguous. |
I feel like I've solved this already with hash_from_list ( https://github.com/notbenh/random_odds_and_ends/blob/master/Data/Manip.pm ) though it's never been posted to CPAN for exactly the reasons stated here, everyone who needs this already built there own or would likely be confused by the idea. The code is a bit more verbose then is needed but it's the same idea. |
The use case schwern used |
I'd forgotten The issue I have with |
I think it's a fairly useful thing to have under certain circumstances. Like you say, smartmatch is O(n) while using a lookup table is O(1). I would much rather generate a hash if I have, say, a huge list I only need to prepare once but might look through hundreds or even thousands of subsequent times. I'd say that's the main usage for such a method anyway, so why not give it a name that's suggestive of same? Like: |
Hello, I am working on this issue for my GCI task. I ran into something I don't quite understand and was hoping someone could explain it to me. So I added this code to the ARRAY.pm file: method as_hash{ But when I try to do: |
It works for me™. There's few possibilities.
|
* 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
Bump the future version number for a feature change. For #172
There was a lot of debate over minor details of this, but on the principle of "the patch wins", I've merged in @qrazhan's work. It implements a straightforward Now we get to see how/if it's used. There's always 3.0 if it turns out to be not quite right. Congrats and thanks for your first patch, @qrazhan! |
I write this a lot:
Usually because I want to check if there's an element in @array a lot.
So
my %hash = @array->as_hash
seems sensible. Should it do anything else?The text was updated successfully, but these errors were encountered: