holli is correct, you don't really want to implement it that way, a hash of hases or Array of arrays, etc, would be much more appropriate.
That being said there is a way to do what you want that being inserting your own entry into the symbol table, thusly:
use strict; use warnings;
{
no strict 'refs';
# Create the 001 hash
*{ "main::001" } = { akey => 'avalue', bkey => 'bvalue' };
# alias the 001 hash to some common name
*{ "main::thehash" } = *{ "main::001" };
}
# show contents of 001 hash
while ( my($k,$v) = each(%001) )
{
print "$k => $v\n";
}
# should be same as above, some monk smarter than I may
# be able to tell why the 001 name got imported but not,
# thehash into the main:: package.
while ( my($k,$v) = each(%main::thehash) )
{
print "$k => $v\n";
}
Again let me say this is a sub-optimal solution, an actuall datastructure would serve you better here, and be much more maintainable and readable. This post is knowledge for knowledge's sake.
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.