array name ARRAY regexp 
Author Message
 array name ARRAY regexp

Hi All,

I have the following case:

The array Parm contains the following names:
use_8 use_10 local_proj_10 note_8 rnr_8 ec_project_8 note_10 ww user command

I've written the following cmd:
foreach ele [array names Parm {use_*} {
    regsub {use_} $ele {} ele
    lappend content_to_use $ele

Quote:
}

foreach id $content_to_use {
    set data_items [array name Parm "_$id"]

Quote:
}

exit 0

I've also tried eval & set cmd "array name Parm _$id" but no matches... what
am I missing?

Thx! in advance
-dimitrius



Tue, 22 Mar 2005 00:47:59 GMT  
 array name ARRAY regexp
Hi All,

Nevermind... the expression was wrong... thx!
-dimitrius

Quote:
> Hi All,

> I have the following case:

> The array Parm contains the following names:
> use_8 use_10 local_proj_10 note_8 rnr_8 ec_project_8 note_10 ww user
command

> I've written the following cmd:
> foreach ele [array names Parm {use_*} {
>     regsub {use_} $ele {} ele
>     lappend content_to_use $ele
> }

> foreach id $content_to_use {
>     set data_items [array name Parm "_$id"]
> }

> exit 0

> I've also tried eval & set cmd "array name Parm _$id" but no matches...
what
> am I missing?

> Thx! in advance
> -dimitrius



Tue, 22 Mar 2005 00:57:21 GMT  
 array name ARRAY regexp

Quote:

> The array Parm contains the following names:
> use_8 use_10 local_proj_10 note_8 rnr_8 ec_project_8 note_10 ww user command

> I've written the following cmd:
> foreach ele [array names Parm {use_*} {
>     regsub {use_} $ele {} ele
>     lappend content_to_use $ele
> }

> foreach id $content_to_use {
>     set data_items [array name Parm "_$id"]
> }

You could simplify this into a single foreach loop:

    set data_items [list]
    foreach element [array names Parm {use_*}] {
        set suffix [string range $element 4 end]
        set data_items [concat $data_items [array names Parm "*_$suffix"]]
    }
    puts $data_items
    # ==> use_8 ec_project_8 rnr_8 note_8 local_proj_10 use_10 note_10

--
Glenn Jackman



Tue, 22 Mar 2005 04:15:32 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Problem with array names -regexp

2. array names -regexp???

3. how to access arrays with variable for array names and index

4. access to array if name of array is variable

5. HOWTO: reference elements of an array if array name is in a variable

6. Problem with with Array of U8 to Array of Array of Boolean

7. convert 2d array to 1d array without using shift registers and build array

8. Arrays: Build array in multiple for loops or replace array elements

9. Multidimensional array vs. array of array

10. Question about array ops on arrays of types of arrays of ...(ack)

11. adjustable-array-p, adjust-array and array-destruction

12. [array names -inorder name]

 

 
Powered by phpBB® Forum Software