ok. thats what I wanted to confirm. I my crude code, I was doing
exactly that and was
wondering if there is some other way to make an entry without really
adding value.
Maybe, perl has to do it internally but will be much more optimal than the one
I am simply forcing a value of 1

Regards

On Thu, Mar 20, 2008 at 9:19 PM, Andrew Curry <[EMAIL PROTECTED]> wrote:
>   %hash = map { $_ => 1 } @array;
>
>              is just a funny way to write
>
>                  %hash = ();
>                  foreach $_ (@array) {
>                      $hash{$_} = 1;
>
>
>                  }
>
>  -----Original Message-----
>  From: Sharan Basappa [mailto:[EMAIL PROTECTED]
>  Sent: 20 March 2008 15:47
>  To: Chas. Owens
>  Cc: Robert Leibl; Perl Beginners
>  Subject: Re: find an entry in hash array
>
>  Can you throw some light on this statement:
>  my %hashset = map { $_ => 1 } @array;
>
>  On Thu, Mar 20, 2008 at 9:14 PM, Chas. Owens <[EMAIL PROTECTED]>
>  wrote:
>  > On Thu, Mar 20, 2008 at 11:35 AM, Sharan Basappa
>  >
>  > <[EMAIL PROTECTED]> wrote:
>  >
>  > > Well here is what I am trying to do.
>  >  >  I have an array (generated from somewhere) I would like to convert
>
>  > >  this into an associative array and then based on some other input
>  > >  I would like to see if an entry exists in the asso array. As you
>  > can see  >  the value does not really matter. What matters is whether
>  > the entry  >  exists or not.
>  >  >  For example (very trivial one)
>  >  >  I have a list of names that are allowed access to a machine. I
>  > create a asso  >  array of them. Later when I want to check if the
>  > user is allowed to login, I  >  check if that user exists or not.
>  > Currently I am doing this by making value for  >  key as 1. But I
>  never really use the value at all.
>  >  >  Regards
>  >  snip
>  >
>  >  This data structure is called a hash set.  Hash sets are easy to make
>  in Perl:
>  >
>  >  #!/usr/bin/perl
>  >
>  >  use warnings;
>  >  use strict;
>  >
>  >  my @array   = qw<a d f h>;
>  >  my %hashset = map { $_ => 1 } @array;  for my $letter ("a" .. "i") {
>  >         if (exists $hashset{$letter}) {
>  >                 print "$letter is in the hash set\n";
>  >         } else {
>  >                 print "$letter is not in the hash set\n";
>  >         }
>  >  }
>  >
>  >  a is in the hash set
>  >  b is not in the hash set
>  >  c is not in the hash set
>  >  d is in the hash set
>  >  e is not in the hash set
>  >  f is in the hash set
>  >  g is not in the hash set
>  >  h is in the hash set
>  >  i is not in the hash set
>  >
>  >
>  >  --
>  >
>  >
>  > Chas. Owens
>  >  wonkden.net
>  >  The most important skill a programmer can have is the ability to
>  read.
>  >
>
>  --
>  To unsubscribe, e-mail: [EMAIL PROTECTED] For additional
>  commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
>
>
>
>  This e-mail is from the PA Group.  For more information, see 
> www.thepagroup.com.
>  This e-mail may contain confidential information.
>  Only the addressee is permitted to read, copy, distribute or otherwise use 
> this email or any attachments.
>  If you have received it in error, please contact the sender immediately.
>  Any opinion expressed in this e-mail is personal to the sender and may not 
> reflect the opinion of the PA Group.
>  Any e-mail reply to this address may be subject to interception or 
> monitoring for operational reasons or for lawful business practices.
>
>

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


Reply via email to