Many thanks to all who contributed in answer to my query - with the help of the Perl Monks, I am now most of the way there (though I had to dump the database idea in favour of a flat file - such is life!).
However, I do have one small puzzle remaining, which perhaps someone could help me with:
In one place, I need to add another record to my array of records, but only after checking all other records associated with that key, to make sure that the record I am adding is not a duplicate.
So I need to test if I am at the end of the array, by checking a counter variable against the number of elements in the records array for the current key. I would have thought that the correct code would be along the lines of:
if ($i < @{$db{$key}})
...
This is similar to the 'for' loop in ikegami's excellent example code. And I have seen something similar used in other code samples concerning hash-of-arrays structures. But when I print out the value of '@{$db{$key}}', I get:
ARRAY(0xfdb30)
Obviously, I would have expected to get an integer. Does the fact that my array elements contain another level of arrays (unlike the other examples I have seen) mean that I need a different test? Or is this simply a side-effect of 'print'?
Can I rely on using '@{$db{$key}}' in my test, or would anyone like to suggest something different??
Thanks in advance for any further guidance you can give me!
Graham Scott.
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.