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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |