Multiple field associative array 
Author Message
 Multiple field associative array

Is it possible to create an associative array that contains multiple
fields for each key?  As in:

  %array = {
    'key1', 'abc', 'def',
    'key2', '123', '456',
    'key3', 'uvw', 'xyz',
  };

I realize this doesn't do what I'm asking, but hopefully it
illustrates what I'm looking for.

--
-------------------------------------------------------------------
      Dan Peterson - InterServ, Seattle, WA


-------------------------------------------------------------------



Wed, 19 Jun 1996 02:53:21 GMT  
 Multiple field associative array

: Is it possible to create an associative array that contains multiple
: fields for each key?  As in:

:   %array = {
:     'key1', 'abc', 'def',
:     'key2', '123', '456',
:     'key3', 'uvw', 'xyz',
:   };

Well, more like:
        %array = (
                'key1', 'field1:field2:field3',
                'key2', 'blah:blah:blah',
                'key3', 'waffle:waffle:waffle',
        )

Choose a field delimiter that cannot appear within your data :-).

: I realize this doesn't do what I'm asking, but hopefully it
: illustrates what I'm looking for.

: --
: -------------------------------------------------------------------
:       Dan Peterson - InterServ, Seattle, WA

-- Peter



Wed, 19 Jun 1996 20:31:26 GMT  
 Multiple field associative array

Quote:


>: Is it possible to create an associative array that contains multiple
>: fields for each key?
>    %array = (
>            'key1', 'field1:field2:field3',
>            'key2', 'blah:blah:blah',
>            'key3', 'waffle:waffle:waffle',

Or wait for perl 5 (or use the alpha release):

        $array{'key1'} = [ 'abc', 'def' ];

You can achieve the desired effects with Perl 4, at some price in black
magic:


        ...
        *k = $_array{'key1'};           # Er - does this leak memory?
        $k[0] == 'abc';
Ian



Thu, 20 Jun 1996 06:32:48 GMT  
 Multiple field associative array

:Or wait for perl 5 (or use the alpha release):
:       $array{'key1'} = [ 'abc', 'def' ];

:You can achieve the desired effects with Perl 4, at some price in black
:magic:
:

:       ...
:       *k = $_array{'key1'};           # Er - does this leak memory?
:       $k[0] == 'abc';

Does it lose memory.  Probably not, assuming that what *k referenced
before is still around.  The real danger is that assignments to typeglobs
anywhere other than within a local() are perilous (can sometimes cause
coredumps or worse) in Perl4, although are ok in Perl5.

--tom
--

      "Will Hack Perl for Fine Food and Fun"
        Boulder Colorado  303-444-3212



Fri, 21 Jun 1996 05:13:12 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. How to sort associative array by field?

2. associative arrays with variable numbers of fields

3. Sorting associative array by record field (perl V4.036)

4. How to sort associative array by field?

5. Sorting Associative arrays then matching one field to a database

6. How to sort associative array by field?

7. associative array or associative arrays

8. Associative array of associative arrays

9. QUESTION...multiple associative arrays as function parms

10. CGI - Multiple values in an associative array

11. using multiple array fields in foreach

12. _value_ -1 in the first field of GLOBAL multi-field arrays

 

 
Powered by phpBB® Forum Software