Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Add Hash Key Based on Matching Another Key

by jethro (Monsignor)
on Jul 28, 2010 at 14:53 UTC ( [id://851732]=note: print w/replies, xml ) Need Help??


in reply to Add Hash Key Based on Matching Another Key

That's what hashes are for. First create a hash with the mac address as key and the hash pointer as value (the advantage is you need to do this only once):

my %macs; foreach @aps { $macs{$_->{'ap_MAC'}}=$_; }

then your loop is reduced to this:

$macs{"00:00:00:00:00:00"}{'serial'} = "FTX12345678";

If you often need to know the array index too, you might store the index number as value into the hash instead of the pointer

Replies are listed 'Best First'.
Re^2: Add Hash Key Based on Matching Another Key
by spickles (Scribe) on Jul 28, 2010 at 15:51 UTC
    Thanks everyone! Just what I needed.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2025-07-13 21:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.