in reply to Search an array for a pair of matching elements
It sounds like the data structure you want is a hash of hashes, like so:
$hostdata = { host1 => { user1 => "info1", }, host2 => { user2 => "info2", user17 => "info39", }, # ... };
In this case, assuming userM exists on hostN, to get the info for that user you'd just use:
$info = $hostdata->{hostN}->{userM}; # the second "->" is optional
There are issues like this, such as autovivification, but you can read up on that if you like. (You should, actually.)
And as for your original question: assuming data integrity, that is, the array size is a multiple of three, you can just run an index from 0 up, incrementing it by 3 every time, and return a result if ($array[$i] eq $host && $array[$i + 1] eq $user) .
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Search an array for a pair of matching elements
by Anonymous Monk on Oct 27, 2004 at 08:06 UTC |