Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


variable manipulation problem

variable manipulation problem

variable manipulation problem

I would like to modify the following code to make it work:
set i 0
set arg$i {C:/Program File/hell0}
regsub -all -- {/} $arg$i "\x5c" arg$i

I get an error when running this code for the regsub line saying "can't read arg, no such variable". This is true but arg0 does exist and $i is a 0.
Could someone please help with this?

RE: variable manipulation problem

Hi fhutt,

I would do that using hash like this:


set i 0
set arg($i) {C:/Program File/hell0}
puts "arg($i) = $arg($i)"
regsub -all -- {/} $arg($i) "\x5c" arg($i)
puts "arg($i) = $arg($i)" 



C:\_mikrom\Work>tclsh fhutt02.tcl
arg(0) = C:/Program File/hell0
arg(0) = C:\Program File\hell0 

RE: variable manipulation problem

Hi microm,
I had this problem before. I couldn't remember how I fixed it, so I did some trial and error. What I came up with is to replace $arg$i with [set arg$i]. Once I got this to work it came back to me that this is what I did before.
However, I prefer your more consistent solution.
Thank you very much.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close