Hi. my problem is simple but i couldnt find the answer since im a newbie. I have created a hash of hashes. Something like this.
%a = {} ;
$a{"KEY1"}->{"VALUE1"}->{key} = value11 ;
$a{"KEY1"}->{"VALUE2"}->{key} = value21 ;
$a{"KEY2"}->{"VALUE1"}->{key} = value11 ;
$a{"KEY2"}->{"VALUE2"}->{key} = value21 ;
So u see, there is a hash, whose keys have values that each point to another hash. Basically im storing some network data which is initially indexed by the source MAC address and for each source MAC address i have several destination MAC addresses. and then for each of these source destination pairs i have some key value pairs like numBytesTransferred, numRetries etc.
The problem
------------
1. foreach $source (keys %allData)
2. {
3. foreach $dest ( keys $allData{$source} )
4. {
5. #access the values
6. }
7. }
Line 3 has an error that says "Type of arg 1 to keys must be hash (not hash element) at file.pl.."
Please help ! or suggest some alternative better way to organize the data that I have talked abt above. Thanks in advance.
MJ
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.