You could give the $tho object a method that advances by one row. Then your sample usage is something like this..
my $tho = tie %th, 'My::DB::User', {-data=>\%nu};
while (exists $th{'username'}) {
print "username is: $th{'username'}\n";
$tho->nextRow;
}
If you want to consider more arbitrary APIs and tie is not doing what you want in terms of overloading behaviour, you can play games with
overload instead.
However my suggestion is that your API will quickly become so arbitrary that would-be users will have a hard time figuring out how it could possibly do what it does under the cover, and will get very confused. Were I going from scratch, KISS tells me to seriously consider not setting any tie anywhere because I don't see how it is clarifying my API.
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.