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

lindex 1

Status
Not open for further replies.

GRonken

Programmer
Oct 30, 2003
26
0
0
US
I want to open a file and get the line, break it into a list.

This is my input file, want it broken into a list showing only the 6th element.

RESULTS;305596;000577672;LMH;F;JEF;;;;;;;;;;"09/30/2003";0857;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1;000577672;

I can open a file ... an put the line in $inline

set msgin [list [lindex $inline 6]]

what am I missing here?
 
The
Code:
lindex
parameter should be a list and you give it a string.
In such a case Tcl tries to interpret the string as a list applying an implicit
Code:
split
command. This implicit command splits the string at all 'blank' characters (space, tab, newline).
Here you need to split the string at all
Code:
;
character. So you need to explicit the
Code:
split
command:
Code:
  set splitted [split $inline \;]
  set sixth [lindex $splitted 6]
or
Code:
  set sixth [lindex [split $inline \;] 6]
More on split at:
HTH

ulis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top