in reply to Re: Link a hash and an array
in thread Link a hash and an array
That is close, but not exactly what I want to do.
I did not put enough detail in my starting post.
I have an array of values, the first one of which indicates what sort of data is in the array. I also have a set of arrays that indicate what fieldnames should be associate with the array.
Think of the array as sometimes being name and address, and sometimes name and phone number. I want to read $ARRAY[0] and then decide how the hash will be created. What I tried to do that does not work is this:
But, of course, that does not work exactly like that, so I am trying to get close. Skip@Address=qw(type firstname lastname streetaddress city zip); @Phone=qw(type name phonenumber); %Stuff; sub ReadStuff{ if ($@_[0]='addr') {%Stuff(@Address)=@_}; elsif ($@_[0]='phone'){%Stuff(@Phone)=@_}; ...do something useful... } @data=(addr, bob, smith, 1234 main st, anytown, 20500); &ReadStuff(@data); @data=(phone, bob, smith, 212-555-1212) &ReadStuff(@data)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Link a hash and an array
by revdiablo (Prior) on Mar 11, 2004 at 22:54 UTC | |
by SkipHuffman (Monk) on Mar 12, 2004 at 15:45 UTC | |
by SkipHuffman (Monk) on Mar 12, 2004 at 16:23 UTC | |
by revdiablo (Prior) on Mar 13, 2004 at 00:01 UTC | |
|
Re: Re: Re: Link a hash and an array
by QM (Parson) on Mar 11, 2004 at 21:30 UTC | |
by SkipHuffman (Monk) on Mar 12, 2004 at 15:52 UTC | |
by QM (Parson) on Mar 12, 2004 at 16:35 UTC | |
by SkipHuffman (Monk) on Mar 12, 2004 at 17:52 UTC |