Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

TCL(Tool Command Language) Scripting

searching array indices


Hello,
I'd like to search array indices against
the below patterns. Can this be done more
efficiently?

So label could be a value as:
"name"

I'm interested in all array elements
that are name only, name.*, *.name or
*.name.*. Note that "aname" or "namePlus"
should not match.

Currently, this works fine, but I'd like to
make it more efficient.

         array set recs [array get out $label]
         array set recs [array get out *.$label]
         array set recs [array get out $label.*]
         array set recs [array get out *.$label.*]

THANKS!

ap wrote:
> Hello,
> I'd like to search array indices against
> the below patterns. Can this be done more
> efficiently?

Read the array man page. It describes the command "array names" which
does what you want.

--
Bryan Oakley
http://www.tclscripting.com

Bryan Oakley wrote:
> ap wrote:
>> Hello,
>> I'd like to search array indices against
>> the below patterns. Can this be done more
>> efficiently?

> Read the array man page. It describes the command "array names" which
> does what you want.

In particular, using the -regexp option you can get all matching
elements in a single pass:

  set keys [array names out -regexp \
      "^(.*\\.)?${label}(\\..*)?$"]
  foreach key $keys {
      set recs($key) $out($key)
  }

You'll have to [time] to see if this actually faster though.

-- Neil

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc