Jan Eden wrote: > > Rob, I read the perlfaq paragraph you mentioned and found that it proposes a > solution which does not make use of 'exists': > > @blues = qw/azure cerulean teal turquoise lapis-lazuli/; > %is_blue = (); > for (@blues) { $is_blue{$_} = 1 }
It's not for me to rewrite the docs (or perhaps it is?) but for (@blues) { $is_blue{$_} = 1 } does the same thing as @[EMAIL PROTECTED] = (1) x @blues; but (I would guess) the former is slower because it has a source-level loop. That means that it's the equivalent to @[EMAIL PROTECTED] = (); (which the parallel to my code) except that the value for each hash element is '1' instead of 'undef', which means that you could write the tidier if ($is_blue{$_}) instead of if (exists $is_blue{$_}) > Now, I had the idea to combine your hash slice with this solution doing: > > @blues = qw/azure cerulean teal turquoise lapis-lazuli/; > @[EMAIL PROTECTED] = 1; > > But since I have only a single number on the right side of the assignment > function, only one hash element gets 1. Is there a way to automatically assign > "1" to all elements with the hash slice notation (i.e. without using a loop)? I think I just showed you that before you asked. You need as many '1's as there are hash elements, so you need to assign 'scalar @blues' copies of the list '(1)'. @[EMAIL PROTECTED] = (1) x @blues > I promise to drop the subject after this question. ;) Believe me, we're really having fun thinking around your ideas: it's better than working for a living :) While you're learning, please keep asking. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>