SPUG: Reference to a hash

Martin, Asa asa.martin at attws.com
Fri Mar 22 12:58:34 CST 2002


That would work for Parents, but not for all fields because, although my
sample didn't show it, Parents isn't the only embedded record within a
record like that. And sometimes the keys of the embedded field aren't always
the same, some are different. For example:

{
        ObjectName=name;
        ClassName=1.3.6.1.4.1.9.1.258;
        NetAddress=xxx.xxx.xxx.xxx;
        NetProtocol=0;
        Type=1;
        AccessString=******;
        LayoutHint=0;
        Action=0;
        Parents={
                        __item__=xxx.xxx.xxx.xxx;
                        __item__=name;
                        __item__=xxx.xxx.xxx.xxx;
        };
        ifIndex=15;
        ifDescr=Vlan;
        ifAlias=;
        ifSpeed=1000000000;
        ifAdminStatus=1;
        locIfDescr=;
        ifType=6;
        HSRPGroupAddresses={
                        HSRPAddress1=xxx.xxx.xxx.xxx/255.255.255.128;
        };
        SnmpStatus=NoAccess;
        InapNeLifeCounter=1;
        Locator=1.0.14.0.0.12.1.0.0.0.6.0;
};

-----Original Message-----
From: Matt Tucker [mailto:tuck at whistlingfish.net]
Sent: Friday, March 22, 2002 10:38 AM
To: Martin, Asa
Cc: spug-list at pm.org
Subject: RE: SPUG: Reference to a hash


-- "Martin, Asa" <asa.martin at attws.com> spake thusly:

> As I went through the loop I had to set "flags" to know where I was in
> processing. The %hash was for the Parents field. It wasn't finished
> until I hit '};'. Then I would assign it to
> %HoH{$recordnum}{Parents}. And since all the keys of %hash were
> __item__ I also had to create a small subroutine that made the key
> unique. What joys.

Since there's no associated key, why not just use an array? It seems
like you're representing a list for the Parents field; it would make
sense to use one:

    %HoH{$recordnum}{Parents} = [ @parents ];


> In addition, some of the fields, like sysDecr
> above split over multiple lines. It was kind of challenging. But I've
> got it figured out now. 
> 
> Thanks again for everyone's input.


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org





More information about the spug-list mailing list