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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Identifying an open unbalanced brace in a string

Status
Not open for further replies.

eugene42

Programmer
Sep 25, 2011
6
US
Hi,

I need to execute a script which parses through the data line, by line. While going through the data, I come across lines which contain unbalanced braces within the data.

I was able to assign it to a list, however, while performing something like

set x [lindex $line 0]

,an error is reported mentioning there's an unbalanced brace. Now, I tried using the split function but it leads to unnecessary empty elements if there's whitespace anywhere in the line, which sounds inefficient and also doesn't help my cause(coz now my problem is deleting the extra elements, and I would need lindex 1,2... I guess u get the point...)

Also, quite obviously, I can't go ahead and manipulate the data and fetch any random [lindex $temp_line 0]

% gets $file_handler line

# Let line value be
#
# assign some_thing = {some_thing1, some_thing2,

% set temp_line $line
% set x [lindex $line 0]
>> ERROR!!

Please help me out !! (I've been cracking my head over this for some time now!! I've tried using regexp, regsub too!!)
 
Code:
% set s "assign some_thing = "
assign some_thing =
% append s \x7b
assign some_thing = {
% append s "some_thing1, some_thing2,"
assign some_thing = {some_thing1, some_thing2,
% regsub \{ $s \| s
1
% set s
assign some_thing = |some_thing1, some_thing2,
%

_________________
Bob Rashkin
 
Hi

eugene42 said:
I need to execute a script which parses through the data line, by line.
So your goal is to process Tcl code in a variable and you have problem when the code is not complete yet ? Then see [tt]info complete[/tt].


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top