[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Thingies



Greetings --

(Apologies if this is a FAQ; the Camel is less than clear on this
point, so I thought I'd come here.)

I've hit a point in my coding where I need to use some references. I've
got a series of arrays, and an array with references to each array.
Depending on user input, some (but not necessarily all) of those arrays
will get initialized, processed, and output. (See code below.)

<code snip>

#! perl -w
use strict;
$|=1;

#declare
my ( @set0 ) = ();
my ( @set1 ) = ();
my ( @set2 ) = ();
my ( $set )  = "";
#set up reference array and name index
my ( @testArray )      = ( \@set0 , \@set1 , \@set2 );
my ( @testArrayNames ) = ( "set0" , "set1" , "set2" );

#simulated user input
@set0 = ( 1 , 2 , 3 );
@set1 = ( 7 , 8 , 9 );

#simulated processing
for ( my $i = 0 ; $i < @testArrayNames ; $i++ ) {
  if ( defined ( @{$testArray[$i]} ) ) {
    print "$testArrayNames[$i]\n";
    for ( my $j = 0 ; $j < @{$testArray[$i]}  ; $j++) {
      print "\t$testArray[$i]->[$j]\n";
    }
  }
}
</code snip>

Here's my problem: I like to give feedback ( print "Now doing X..."; ),
so I'd like to be able to get the name of the array being looked up
without having to have another array with the names (@testArrayNames,
above). Doing this the way I've done it above feels very kludgey, and
it seems like there should be a better way -- some way to deref
$testArray[$i] to get the name of the referenced array.

Thanks for any help,
john.
-- 
----------------------------------------------------------------
John S Jacobs Anderson                      jacobs@azstarnet.com
www.treefort.org/~jacobs/ <--   GeneHack (bioinfo*linux*opinion)
Data/Spock '96  the Logical Choice!


===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org