Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HASH issues

Status
Not open for further replies.

Firemyst

Programmer
Mar 10, 2003
62
US
Hi there,

I have the following hash data structure. I have two issues:
1) how do I add to it?
2) how do I reference the lowest level array values from it?

For example, if I want to add another "test" value in the "heading" key of the "datestamp1" key of the "demo1" key, how do I do it?

Similarily, if I later want to print that value, how do I reference it?

I can't seem to figure it out.

Thanks!

%cals => {
"demo1" => {
"datestamp1" => {
"heading" => ["test1","test2", ... "testx"]
"event_num" => ["1","2",..."x"]
}
"datestampx" => {
"heading" => ["test1","test2", ... "testx"]
"event_num" => ["1","2",..."x"]
}
}
"demox" => {
"datestamp1" => {
"heading" => ["test1","test2", ... "testx"]
"event_num" => ["1","2",..."x"]
}
"datestampx" => {
"heading" => ["test1","test2", ... "testx"]
"event_num" => ["1","2",..."x"]
}
}
}

 
I do something similar in one of my scripts.
Code:
%enable = (
    #just for testing
    'testvar1' =>
        {
            'directory'    =>    '/tmp',
             'command'     =>    "ls -la /tmp/testvar1
                                  date"
        },
    #qmail
    'alias' =>
        {
            'directory'    =>    $qmaildir,
            'command'      =>    "putdiff.sh /var/qmail/alias alias"
        }

If I want the value for directory under alias, I could reference it like:
Code:
$enable{'alias'}->{'directory'}

Since yours goes a bit deeper, it should just be:
Code:
$foo{'bar'}->{'baz'}->{'quux'}

If you want to add a new value:
Code:
$foo{'bar'}->{'baz'}->{'quux'} = $quuux;

--
Andy
"Historically speaking, the presence of wheels in Unix has never precluded their reinvention."
Larry Wall
 
%cals => {
"demo1" => {
"datestamp1" => {
"heading" => "test1","test2", ... "testx"
"event_num" => "1","2",..."x"
}
"datestampx" => {
"heading" => "test1","test2", ... "testx"
"event_num" => "1","2",..."x"
}
}
OK this is dereferencing issue

try something like this.

$deref = $cals{demo1}->{datestamp1}->{heading}[0]

push $cals{demo1}->{datestamp1}->{heading}[0], $somearay_element;



haunter@battlestrata.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top