michel van berkel wrote:
>
> I an obscure past I used COBOL. I hated it, setting up all these
> division and no real work done.
> But one thing was convenient.
> You could set up:
> 001 Identity
> 003 Name
> 005 FamilyName
> 005 FirstName
> 005 MiddleName
> 003 Address
> 005 Street
> 005 Number
> 005 ZipCode
> 005 City
> 003 PhoneNumber
> 005 CityCode
> 005 Number
> So you'd have several variables which had it all, Identity would have
> it all, Name would have the complete name aso.
> Is this possible in Perl, I tried to do it using arrays within
> arrays, but now I'm stuck for its complexity reading them back again.
> Is there a simpler way to do this?
I took a Cobol class in college once for some unknown reason. I
vaguely remember this type of stuff.
The best way to do this in Perl is with hashes, not arrays. Try
something like this:
my %person;
$person{Name}{FamilyName} = "Smith";
$person{Name}{FirstName} = "John";
$person{Address}{Street} = "123 Example Blvd";
etc...
You could put this record into an array:
my @addressArray;
push @addressArray, { %person };
print $addressArray[0]{Name}{FirstName} . "\n";
Or another hash:
my %addressHash;
my $fullname = $person{Name}{FamilyName} . ', ' .
$person{Name}{FirstName};
$addressHash{$fullname} = { %person };
print $addressHash{$fullname}{Address}{Street} . "\n";
You don't even have to declare the structure. Perl will build it as
you go. Each element can be whatever you want it to be. This can be
useful, but it can also lead to some really ugly data structures, so
be careful.
--
Bowie
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs