Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

You must login to add post.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Passionable Logo Passionable Logo
Sign InSign Up

Passionable

Passionable Navigation

  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • New Questions
  • Trending Questions
  • Must read Questions
  • Hot Questions
Home/ Questions/Q 9080
In Process
Alek Richter
  • 0
Alek RichterEnlightened
Asked: January 13, 20222022-01-13T11:02:05+00:00 2022-01-13T11:02:05+00:00

square brackets in tcl arrays

  • 0

I have the following problem:

set start "input[0]"
set end   "output[0]"
set myArray($start,$end,pin) 1
set x "input[0]"
set y "output[0]"
set test [array names myArray $x,$y,pin]
puts "\n$test"

output should be:

input[0],output[0]

but output is:

{}

if I do:

set test [array names myArray *,*,pin]
puts "\n$test"

output is:

input[0],output[0]

Also, if I replace [] by {} ie.input{0},output{0} original code works.

Can someone please tell me what is happening here? How do I escape the [] brackets?

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
    • Report
  • Share
    Share
    • Share on Facebook
    • Share on Twitter
    • Share on LinkedIn
    • Share on WhatsApp

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Alek Richter Enlightened
    2022-01-13T11:02:28+00:00Added an answer on January 13, 2022 at 11:02 am

    Well, let’s look what is going on here:

    set start “input[0]”

    This will execute the command 0. I don’t know what that does, but you propably don’t want that. Either escape brackets with \ or use {} to enclose the name.

    Same applies for

    set end “output[0]”
    # …
    set x “input[0]”
    set y “output[0]”

    But it doesn’t look like you have that problem.

    The next thing is that you pass a glob pattern to array names:

    set test [array names myArray $x,$y,pin]

    Tcl uses [] in glob patterns for character choices, simmilar to regexp. So your pattern will only match input0,output0,pin. You can avoid that by passing the -exact switch to array names:

    set test [array names myArray -exact $x,$y,pin]

    Or you can escape the brackets again with a backslash (note that the pattern should look like input\[0\],input\[1\],pin after Tcl did all kinds of substitution.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 4k
  • Best Answers 0
  • Users 2
  • Popular
  • Answers
  • Alek Richter

    When does a process get SIGABRT (signal 6)?

    • 2 Answers
  • Alek Richter

    How do I add sockets to an item?

    • 2 Answers
  • Alek Richter

    Dialog throwing "Unable to add window — token null is ...

    • 2 Answers
  • Alek Richter
    Alek Richter added an answer Pandas DataFrame columns are Pandas Series when you pull them… January 13, 2022 at 2:21 pm
  • Alek Richter
    Alek Richter added an answer The handshake failure could have occurred due to various reasons:… January 13, 2022 at 2:19 pm
  • Alek Richter
    Alek Richter added an answer Mac OS X doesn't have apt-get. There is a package… January 13, 2022 at 2:18 pm

Top Members

Alek Richter

Alek Richter

  • 4k Questions
  • 1k Points
Enlightened

Trending Tags

questin question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • New Questions
  • Trending Questions
  • Must read Questions
  • Hot Questions

© 2021 Passionable. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.