Perl developpers are helpful. Eventhough this list is not dedicated
to stricto sensu Perl programming, I will answer your question, but just
this time. Please refer to the right list (I thing there is a Perl
beginners list), and above all, get the Camel book (Programming Perl
3rd Edition, O'Reilly editors), and take the time to learn this
superb language. It's more than worth it...

So, your statement :

> Name ,123-43-4352, JX, 1234
> Sports,123-43-4352, SKI, BaseBall, swimming
> Hobbies, 123-43-4352, H1,H2, H3
> Hobbies, 123-43-4352, HH, HHH, HHHH2
> Hobbies,123-43-4352, H1,H43
>
> Name ,223-63-9352, JX, 1234
> Sports,223-63-9352, SKI, BaseBall, swimming
> Hobbies, 223-63-9352, H1,H2, H3
> Hobbies, 223-63-9352, HH, HHH, HHHH2
> Here is my issue, I am trying to access each record in this file by SSN
> ie: (223-63-9352)
> I want to be able to say:
> for SSN = 223-63-9352,  for Hobbies4 4th entry is HGFR.

# A solution
# 1. Build a convenient data structure (we suppose that attribute names are normalized)
our %data = ();
while ( <STDIN> ) {
        my ($attribute, $ssn, @values ) = split /\s*,\s*/;
        push @{ $data{$ssn}{$attribute} }, @values;
}

# 2. Then fetch from it (you could write specialized procs for this, or
# even methods if you consider making a component out of this)
my $hobby_fourth = $data{'223-63-9352'}{'Hobbies'}[3]; # By default, Perl starts array 
indexes at 0

You see, it's quite short.


Good luck.

Franck

--------------------
Franck PORCHER
Essential Software
http://www.esoft.pf/
Tél: (689) 56 23 95

Reply via email to