perlquestion
Limbic~Region
All:
<br>
I am currently working on my first OO project and would like to be able to do something like <CODE>$record->Print;</CODE> and have it correctly output the record in the proper format. Unfortunately, the object is stored in a hash - and we know that the hash typically comes out differently than the order it went in.
<p>
For complete details on the OO project, you can take a look at [238963|this] link or you can just readmore for the output format I am looking for:
<br>
<readmore>
<CODE>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=LRegion
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=Limbic_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
</CODE>
</readmore>
<p>
What I have currently looks something like this:
<br>
<CODE>
sub Print {
my $hashref = shift;
my ($key) = keys %{$hashref};
# @Parameters truncated for posting purposes only
my @parameters = ('key','type','flags','Alias-2','Zip Code','Building','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),substr($value,62));
}
else {
printf("%-16s: %s\n",$parm,$value);
}
}
}
</CODE>
<p>
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?
<p>
Thanks in advance - [Limbic~Region|L~R]