For complete details on the OO project, you can take a look at this link or you can just readmore for the output format I am looking for:
key : /C=US/A=BOGUS/P=ABC+DEF/O=CONN/OU=VALUE1/S=Region/G= +Limbi c/I=_/ type : UR flags : DIRM ADMINM ADIC ADIM Alias-2 : wL_Region Alias-3 : Limbic Region Alias-4 : Limbic._.Region@nowhere.com Alias-5 : Limbic._.Region Alias-6 : Limbic.Region@nowhere.com Alias-7 : ORG Alias-8 : CMP Alias-10 : O=ORG/OU=Some Big Division/CN=Limbic _. Region Alias-11 : Region Alias-12 : Region, Limbic _ Alias-14 : Limbic _. Region at WT-CONN Alias-15 : ex:/o=BLANK/ou=ORG/cn=Recipients/cn=Mailboxes/cn=LRe +gion Alias-16 : WT:Limbic_Region Alias-17 : SMTP:Limbic._.Region@nowhere.com Alias-18 : /o=A.B.C.D./ou=Vermont Ave/cn=Recipients/cn=wt/cn=Li +mbic_Regi on Full Name : Region, Limbic _. Post Office : WT-CONN Description : 999-555-1212 Some Big Company Tel : 999-555-1212 Dept : Some Big Division Location : EMWS Address : 123 nowhere street City : everywhere State : MD Zip Code : 20874 Building : BLAH Building-Code : MD-ABC owner : CONN
What I have currently looks something like this:
sub Print { my $hashref = shift; my ($key) = keys %{$hashref}; # @Parameters truncated for posting purposes only my @parameters = ('key','type','flags','Alias-2','Zip Code','Build +ing','Owner') foreach my $parm (@parameters) { next unless ($hashref->{$key}->{$parm}); my $value; if ($parm eq 'key') { $value = $key; } else { $value = $hashref->{$key}->{$parm}; } if (length($value) >= 62) { printf("%-16s: %s\n\t%s\n",$parm,substr($value,0,62),subst +r($value,62)); } else { printf("%-16s: %s\n",$parm,$value); } } }
My question - is there a better/smarter way to do this? I guess what I am asking is there a generic way to template hash output that I am unaware of? Since this is my first OO project, I really didn't know what I was getting into. I think if I were to start over, I would make my object a complex array instead of hash. Is that also the wrong approach?
Thanks in advance - L~R
In reply to Printing a hash in a specific order? by Limbic~Region
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |