Trevor Joerges wrote:

> Key values would not necessarily be unique but you could search the hash for
> keys who have values equal to "1":
> 
> foreach (keys %week) {
>  if ($week{$_} == 1) {
>   print "$_\n";
>  }
> }
> 
> You were probably looking for something like $key = $week{$key} but given
> that values are not necessarily uniqye that would cause problems in a data
> structure of key/value pairs.


Or just reverse the hash so it's set up properly for this:

my %days = reverse %week;
my $wday = $days{$day};


> Hope this helps.
> 
> Kind regards,
> Trevor J. Joerges
> --------------------------------------------
> $_=q;rrUSFWPSZK.ZKPFSHFT,rkvtuZbopuifsZQZibdl
> rrqpxfsfeZcyZQ,,riuuq://xxx.%.dpn,ru~@%.dpn ,rrr8-)
> ;;s;\~;kpfshft;g;s;\%;tfoenjnf;g;y;B-x;A-w;;
> s;P;perl;g;s;,;\n;g;s;Y; ;g;s;q;\t;g;print;
> --------------------------------------------
> 
> ----- Original Message -----
> From: "Marcos Lorenzo de Santiago" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Friday, April 12, 2002 6:59 AM
> Subject: can I get the keys from a hash giving the value?
> 
> 
> : I got a hash:
> :
> : %week=("monday" => 1,
> :        "tuesday" => 2,
> :        "wednesday" => 3,
> :        "thursday" => 4,
> :        "friday" => 5,
> :        "saturday" => 6,
> :        "sunday" => 7
> : );
> :
> : and I have $day=1, can I get then "monday"??



-- 
   ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
  (_/   /  )    // //       DBE Collectibles   Mailto:[EMAIL PROTECTED]
   / ) /--<  o // //      http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/

_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to