I have an hashref that has the following data.
$href = {
'a' => {
't' => {
'x' => {
'2008-08-07' => 1
}
}
}
'b' => {
'd' => {
'o' => {
'2008-08-06' => 1
}
}
}
};
and I have an array with the following data:
@array = ('a', 't', 'x', '2008-08-07');
I know that I could see if
$href->{a}->{t}->{x}->{2008-08-07} exists
by just typing:
if (exists $href->{a}->{t}->{x}->{2008-08-07} ){
print "href value exists";
}
But that would be too statically hard encoded and manual.
I am trying to find a more elegant way to see if the hashref exists
based on a dynamically generated @array values that aren't known yet.
That way I can generate the exists statement corresponding to whatever the array length and values are instead dynamically.
Basically if the array turns out to be:
@array2 = ('b', 't', 'm', 'p');
I'd like to check if:
$href->{b}->{t}->{m}->{p}
exists without typing out "b, t, m, p".
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.