James Edward Gray II wrote:
> 
> On Feb 10, 2004, at 2:39 PM, Jan Eden wrote:
> >
> > @blues = qw/azure cerulean teal turquoise lapis-lazuli/;
> > %is_blue = ();
> > for (@blues) { $is_blue{$_} = 1 }
> >
> > 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;
> 
> @[EMAIL PROTECTED] = (1) x scalar @blues;
> 
> > 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)?
> 
> You could also use map() I guess, if you don't consider that a loop:
> 
> @[EMAIL PROTECTED] = map { 1 } 0..$#blues;

And if you don't really need the @blues array:

my %is_blue = map { $_ => 1 } qw/azure cerulean teal turquoise
lapis-lazuli/;



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to