I have determined the correct methodology ( in my mind ) for the 
Particular problem...

I have a bunch of data:

        $Array[ 0 ] = "some data 1";
      $Array[ 1 ] = "some data 2";
      $Array[ 2 ] = "some data 3";

And I have a function that sets some indices into 
My "Array" based on specific items I know will be in the file(s)
( note these functions are called after some parsing is done
  on a header section of the file, to determine which data 
  should be looked for later on in the file )

#       Set File1_data in 
        sub somefunction1()
        {
                push( @Search, 0 );
                push( @Search, 2 );  # notice the 1 "index" is not here...
        }

#       Set File2_data in 
        sub somefunction2()
        {
                push( @Search, 1 );  # this file only will be Array[ 1 ]
value...
        }



Now I can use the "Search" array generically as follows:
        
        foreach $Index (@Search)
        {
                print " $Array[ $Index ] \n";
        }

Mike

-----Original Message-----
From: R. Joseph Newton [mailto:[EMAIL PROTECTED]] 
Sent: Thursday, January 16, 2003 4:27 PM
To: Liss, Mike
Cc: '[EMAIL PROTECTED]'
Subject: Re: Adding to multi-dimensional array dynamically via push...


push( @MyArray[ 0 ],  0 );

Hi Mike,

I think you need to make up your mind who's doing the work here--you or
Perl.  The stack functions, push and pop, are intended to let the array
handle its own organization, while you concern yourself only with the top
element [ie the one most recently inserted].  Using element indexes is not
compatible with this.  This is the downfall of Perls throwing the array and
stack structures together.

If you wish to address specific array indices, then address them directly,
and do not use push or pop on that array.  If your purpose has to do with
stack dynamics, use push and pop for your top element.  The two approaches
are, IMNSHO, not very compatible.

Joseph

Joseph

Reply via email to