rjsaulakh has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: How do I load a hash table?
by Limbic~Region (Chancellor) on Jan 12, 2005 at 15:17 UTC
    rjsaulakh,
    After spending a fair amount of time trying to explain this to you in the CB, I am going to recap before answering your question.

    A hash key ($nas) is nothing more than a key and it has a corresponding value in the hash. That value may be a reference to another data structure (an anonymous hash). That anonymous hash may have one or more keys ($response_status). Your confusion is in thinking that there is only one possible value in the anonymous hash. In reality, it may have one or more keys. I would suggest the following code instead:

    #!/usr/bin/perl use strict; use warnings; use constant STATUS => 0; use constant REQUEST => 1; # Some code that initializes %list # In the form # $list{ $nas }[STATUS] = $response_status; # $list{ $nas }[REQUEST] = $request_date_time # Later on you can retrieve the status and request like my $mac = ''; # actual code to get MAC from log my $status = $list{ $mac }[STATUS]; my $request = $list{ $mac }[REQUEST];
    You may need to modify it a little if it is possible for a MAC to have more than one status and request date. If that is the case then you need to take some time in figuring out how to ask a question.

    List of links added after initial post

    Cheers - L~R

Re: How do I load a hash table?
by edan (Curate) on Jan 12, 2005 at 15:22 UTC

    Maybe I'm totally misunderstanding you, but I'm envisioning that you have a HoH structure like this:

    my %macs = ( '00:11:22:33:44:55' => { 'response_status' => 12, 'response_date' => 'yesterday', }, 'AA:BB:66:12:13:14' => { 'response_status' => 0, 'response_date' => '2004-12-31', }, # ... and so on );

    And you get some user input, then you look up the data you want:

    my $mac = <STDIN>; chomp $mac; if ( exists $macs{$mac} ) { print "Okay, found mac $mac:\n"; print "response_status: $macs{$mac}{response_status}\n"; print "response_date: $macs{$mac}{response_date}\n"; } else { print "Sorry, don't recognize that mac\n"; }

    Is that what you meant?

    --
    edan

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: How do I load a hash table?
by borisz (Canon) on Jan 12, 2005 at 15:17 UTC
    I assume that a mac-address is not unique in you log. So you better build a array of entries for every mac-address.
    push @{ $list{$macaddress} }, [ $response_status, $request_date_time ] +;
    Boris
A reply falls below the community's threshold of quality. You may see it by logging in.
A reply falls below the community's threshold of quality. You may see it by logging in.