Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Looking up a hash by value

by a (Friar)
on Feb 23, 2001 at 11:16 UTC ( [id://60444]=note: print w/replies, xml ) Need Help??


in reply to Looking up a hash by value

Besides (and you've been at this a while so just do it) -w/use strict and
or die "can't open $path/newestm.txt: $!";
I'm guessing your %whop hash as member names as values and ... well, lets say IP addresses as keys. One way would be:
foreach $newm (@newest_members) { my $online; foreach my $whos_on ( values %whop ) { $online++ if $whos_on eq $newm; } my $star = '<b>*</b>' if $online; print <<EOF; $newm $star - EOF } # foreach newm
yes, wasteful and a map would probably be cool or $who_list = join '|', values %whop; and then if ($newm =~ /$who_list/ but you get the idea.

a

Replies are listed 'Best First'.
Re: Re: Looking up a hash by value
by tomhukins (Curate) on Feb 23, 2001 at 16:49 UTC

    Rather than iterating through %whop, you can use reverse to swap the keys and values of a hash, then use exists:

    my %whop_value = reverse %whop; foreach my $newm (@newest_members) { $newm .= '<b>*</b>' if exists $whop_value{$newm}; $newm .= ' - '; print $newm; }

    Using reverse on hashes is described in perlfunc:reverse

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-03-28 17:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found