Hi, this is closely related to another question I asked here recently, but I'm still struggling to really grok this stuff. :-)
I have a list of hashrefs that I can work with very nicely a la:
foreach my $response ( @ $address ) {
print "name: $response->{Addressee}<br>";
print "street: $response->{Street}<br>";
...etc.
But sometimes I get just a single hash ref with the same data, and what I'd like to know how to do is force it into a list so that I can use the above loop to process it as a single element list. Sounds easy, right? But I'm getting no where with for example:
if ( ref $address eq HASH ) {
my $templist = [ $address ];
}
or
if ( ref $address eq HASH ) {
push my @templist, $address;
}
Which seems logical to me, but when I print or ref the new variable I get nothing, when I'm expecting "ARRAYx...".
Clearly I'm misunderstanding something here..and I'd be grateful for any feedback!
p.s. this is data generated from XML::Simple, and I could use the ForceArray option there, but I just *kinda really want to know how to do it because it's driven me crazy for an hour now* :-)
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.