Re: Accessing the values of HoH



John W. Krahn wrote:
M. Lewis wrote:
In my most recent postings, I was dealing with first HoA and now HoH.

In my previous example code, I ended up with an output that looked
something like this:

jelly -- strawberry apple grape pear
jam -- strawberry apple grape
milk -- plain strawberry chocolate

I thought I'd prefer to have it listed more like this:

jelly -- strawberry
apple
grape
pear
jam -- strawberry
apple
grape
milk -- plain
strawberry
chocolate


So in the following snippet, I tried to add a "\n" onto the value of the
HoH.

for my $i ( keys %HoH ) {
%{$HoH{$i}} = join ("\n", %{$HoH{$i}}, "");
print "$i -- @{[ keys %{$HoH{$i}} ]}\n";
}

Try it like this:

for my $i ( keys %HoH ) {
my $key = "$i -- ";
print $key, join( "\n" . ' ' x length $key, keys %{ $HoH{ $i } } ), "\n";
}


This worked fine John. At first I didn't understand what was going on with the join, but after some sleep and looking at it more, I know understand it. Thanks much John!

Mike


--

The programmer's national anthem is 'AAAAAAAAHHHHHHHH'. -Weinberg, p.152
23:00:01 up 15 days, 19:51, 0 users, load average: 0.30, 0.30, 0.32

Linux Registered User #241685 http://counter.li.org
.



Relevant Pages

  • Re: Accessing the values of HoH
    ... I was dealing with first HoA and now HoH. ... jelly -- strawberry apple grape pear ... milk -- plain strawberry chocolate ...
    (perl.beginners)
  • Re: Charles Aznavour
    ... Or strawberry jam, soaked into the bread. ... My father and I were seriously addicted to eating it by the spoonful, but on baking days my mother had to make not just enough bread to last until the next baking day but she also had to have an extra loaf for my father and me to devour in situ, just barely cooled enough to be sliced, with lashings of butter and Empress jam. ...
    (soc.motss)
  • Re: Time to start preserving
    ... some Barbara Schaller's mango and strawberry jam with kiwi fruit. ... Maybe strawberry jam or jelly. ... ginger from last year in the freezer that might do well there. ...
    (rec.food.preserving)
  • Re: Charles Aznavour
    ... suddenly reminded that it's Welch's Strawberry Preserves which are ... Historically speaking, I would have to disagree with you, painful as ... with lashings of butter and Empress jam. ... strawberry jam is only available at Frank and Lyndol's, ...
    (soc.motss)
  • Re: Charles Aznavour
    ... suddenly reminded that it's Welch's Strawberry Preserves which are ... Historically speaking, I would have to disagree with you, painful as ... with lashings of butter and Empress jam. ... strawberry jam is only available at Frank and Lyndol's, ...
    (soc.motss)