Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2-D Array get problem with variable index

Status
Not open for further replies.

johnlopez2000

Programmer
Aug 2, 2002
90
US
#~ Please note the following array:

% array get xAssignments
{Eng Release,Quality} {doviakg5 lopezj5} {Eng Release,Materials} {doviakg lopezj} {Eng Release,Performance} {doviakg3 lopezj3} {Initial,Big guy} {verginisd lawheadg} {Eng Release,Project} {doviakg4 lopezj4} {Initial,Eng Dude} {verginisd2 lawheadg2} {Initial,Mfg Dude} {verginisd3 lawheadg3} {Eng Release,Mfg Eng} {doviakg2 lopezj2}

#~ when I attempt to ARRAY GET with a search pattern
#~ of the indexes, and the index is "hard coded"
#~ it works as expected:

% array get xAssignments {Initial,*}
{Initial,Big guy} {verginisd lawheadg} {Initial,Eng Dude} {verginisd2 lawheadg2} {Initial,Mfg Dude} {verginisd3 lawheadg3}

#~ however, when I make the array index pattern a variable
#~ it seems that it is not expanding the variable prior to
#~ searching the array with the supplied key

% set key "Initial"
Initial
% array get xAssignments {$key,*}
%

Is there something obvious I am missing?


John Lopez
Enterprise PDM Architect
lopez.john@goodrich.com
 
Don't know but it works fine here.
You are going a little list happy with your brackets.

Code:
>parray xassign
xassign(Eng Release,Materials)   = doviakg lopezj
xassign(Eng Release,Mfg Eng)     = doviakg2 lopezj2
xassign(Eng Release,Performance) = doviakg3 lopezj3
xassign(Eng Release,Project)     = doviakg4 lopezj4
xassign(Eng Release,Quality)     = doviakg5 lopezj5
xassign(Initial,Big guy)         = verginisd lawheadg
xassign(Initial,Eng Dude)        = verginisd2 lawheadg2
xassign(Initial,Mfg Dude)        = verginisd3 lawheadg3
>foreach poss [array name xassign] {
                       if {[regexp "$key" $poss]} {
                           puts "$poss = $xassign($poss)"
                       }
             }
Initial,Big guy = verginisd lawheadg
Initial,Mfg Dude = verginisd3 lawheadg3
Initial,Eng Dude = verginisd2 lawheadg2
>array get xassign $key*
{Initial,Big guy} {verginisd lawheadg} {Initial,Mfg Dude} {verginisd3 lawheadg3} {Initial,Eng Dude} {verginisd2 lawheadg2}

HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top