Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Array to Hash

by plaid (Chaplain)
on May 10, 2000 at 20:38 UTC ( #10997=note: print w/replies, xml ) Need Help??

in reply to Array to Hash

Yet another way
map { $hash{$_} = 1 } @array;

Replies are listed 'Best First'.
RE: Re: Array to Hash
by merlyn (Sage) on May 12, 2000 at 19:23 UTC
    no. no map in void context please. That's what you have the backwards foreach for.
    $item{$_} = 1 for @list;
      What is so bad about map in map in void context ? I mean no harm can be done, can it ?

        Just in case others Super Search for an answer to this question and follow merlyns node mentioned first in the result-set, here is the relevant excerpt of the perlfaq6

        Found in /usr/lib/perl5/5.8.0/pod/perlfaq6.pod
        What's wrong with using grep or map in a void context?

        The problem is that both grep and map build a return list, regardless of the context. This means you're making Perl go to the trouble of building a list that you then just throw away. If the list is large, you waste both time and space. If your intent is to iterate over the list then use a for loop for this purpose.


        Hlade's Law:

        If you have a difficult task, give it to a lazy person --
        they will find an easier way to do it.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://10997]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2022-05-29 12:07 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (101 votes). Check out past polls.