Hi Mark.Allan

As with tangent my solution assumes that 'current' and 'tis' contain the same number of items.

I am not sure if my solution is any better ( six of one, half a dozen of the other), but you can change the order of the PRINT_ORDER array to easily change the order of the output. At the very least, I had fun with this one. :)

Update: I removed a testing line I had in there for SUB_GROUP.

use strict; use warnings; my %_COLLECTION_HOH = ( 'AUTO' => { 'category' => 'Shelf', 'division' => 'deployment', 'priority' => '3', 'resolved' => 'YES', 'current' => 'CLOSED2/1 CLOSED2/2 CLOSED2/3 CLOSED2/4', 'tis' => '200 300 400 200', 'customer' => 'NO', 'worker' => 'YES', }, ); my @PRINT_ORDER = qw(category division priority resolved current tis c +ustomer worker); for my $PARENT_GROUP ( keys %_COLLECTION_HOH ) { ## Split up items in the 'current' and 'tis' sets and remove extra + whitespace my @CURRENT_ITEMS = map{s/^\s+//;s/\s+$//;$_} split(/\n/, $_COLLE +CTION_HOH{$PARENT_GROUP}{'current'} ); my @TIS_ITEMS = map{s/^\s+//;s/\s+$//;$_} split(/\n/, $_COLLE +CTION_HOH{$PARENT_GROUP}{'tis'} ); ## Assumes that 'current' and 'tis' have an equal number of items for (my $CURRENT_ITEM_ITER = 0; $CURRENT_ITEM_ITER <= $#CURRENT_IT +EMS; $CURRENT_ITEM_ITER++) { my $value = undef; print "$PARENT_GROUP,"; for(0..$#PRINT_ORDER) { if ($PRINT_ORDER[$_] eq 'current') { $value .= "$CURRENT_ITEMS[$CURRENT_ITEM_ITER]," if + $_ <$#PRINT_ORDER; $value .= "$CURRENT_ITEMS[$CURRENT_ITEM_ITER]" if +$_ == $#PRINT_ORDER; } elsif ($PRINT_ORDER[$_] eq 'tis') { $value .= "$TIS_ITEMS[$CURRENT_ITEM_ITER]," if $_ +<$#PRINT_ORDER; $value .= "$TIS_ITEMS[$CURRENT_ITEM_ITER]" if $_ = += $#PRINT_ORDER; } else { $value .= "$_COLLECTION_HOH{$PARENT_GROUP}{$PRINT_ +ORDER[$_]}," if $_ <$#PRINT_ORDER; $value .= "$_COLLECTION_HOH{$PARENT_GROUP}{$PRINT_ +ORDER[$_]}" if $_ == $#PRINT_ORDER; } } print "$value\n"; } }

In reply to Re: Printing hash values by VincentK
in thread Printing hash values by Mark.Allan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.