Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2026-11-13
11:18 • Closed ticket [673725ffff]: splitx in core plus 6 other changes artifact: f2eb69550e user: serhiy.storchaka
2003-02-23
00:31 • Ticket [673725ffff]: 1 change artifact: 48b0c7a246 user: dkf
2003-02-20
22:57 • Ticket [673725ffff]: 6 changes artifact: c85b8ef976 user: dkf
2003-01-24
11:25 • Ticket [673725ffff]: 4 changes artifact: a25a56e306 user: dgp
09:02 • Ticket [673725ffff]: 2 changes artifact: 9e4124ef97 user: andreas_kupries
09:01 • Ticket [673725ffff]: 7 changes artifact: d4865c52e6 user: andreas_kupries
08:05 • Ticket [673725ffff]: 4 changes artifact: 9ba7f03220 user: nobody
00:56 • New ticket [673725ffff]. artifact: 3fe713c94c user: nobody

splitx in core

Closed / Wont Fix673725ffffffffffffffffffffffffffffffffffCreated 24 years agoUpdated 19 days ago
Descriptionplain2003-01-24 00:56:03
split command does not handle multiple white space properly. 

TCL split should work like the Perl split command. I know its 
documented that's the way TCL split works. But what we want is 
the valid data not a bunch of null token {}  tht have to be 
discarded by a few more line of code.

Example: 
$line = 1     2     3     4     5  (mutiple spaces between the numbers)

Perl:
parts[] = split ( ' ' , $line)
produces an array with the 5 numeric tokens 1,2,3,4,5

TCL:

set parts [split $line]
produces an array with 1 {} {} {} {} {} 2 {}  etc
Then you have to get rid of the {} by extracting to another array 
only the valid numeric tokens 1,2,3,4,5
nobodyplain2003-01-24 08:05:38
Logged In: NO 

Example:
Instead of the following manipulation to do a split

foreach sym [split $symbol_list] {
    if {[string length $sym] == 0} continue
    set ticker_symbols([incr i]) $sym
}

Should only have to do the following

set ticket_symbols [split $symbol_list ]
andreas_kupriesplain2003-01-24 09:01:11
Logged In: YES 
user_id=75003

This is not a bug. The very usage of "should work" makes it
already a feature request. Switched categorization. Another
workaround than described in the comments is to 

    regsub {  *} $line { } newline

to get rid of sequences of more than one spave and then to
[split] the $newline.
andreas_kupries Ticket [673725ffff]: 2 changes [History diff]2003-01-24 09:02:14
dgpplain2003-01-24 11:25:39
Logged In: YES 
user_id=80530

The original requester wants this:

package require textutil
namespace import textutil::splitx
rename split {}
rename splitx split

There.  Now [split] does what he wants.

Be warned that this may break packages
that expect the [split] command to behave as
documented in Tcl.  (It's possible this will even
break the textutil package itself.  Haven't tested.)
But for your own limited purposes this might be an option.
dkfplain2003-02-20 22:57:18
Logged In: YES 
user_id=79902

The original requester could use this:
  set parts [regexp -all -inline {\S+} $line]

Since there's such a trivial workaround, I'll change the
title to indicate what they're really after.
dkf Ticket [673725ffff]: 1 change [History diff]2003-02-23 00:31:06
serhiy.storchakawiki2026-11-13 11:18:45

Closing: the alternatives given above cover this, and adding splitx to the core never got a TIP.

Log in (anonymous is fine) to add a comment.