Tcl Source Code

View Ticket
Login
Ticket UUID: 673725
Title: splitx in core
Type: RFE Created on: 2003-01-24 00:56:03
Submitter: nobody Assigned to: dkf
Subsystem: 18. Commands M-Z Severity:
Priority: 5 Medium Last modified: 2026-11-13 11:18:45
Status: Closed Closed by: serhiy.storchaka
Resolution: Wont Fix Closed on: 2026-11-13 11:18:43
Version: None
Description:
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
User Comments:
nobody added on 2003-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_kupries added on 2003-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.

dgp added on 2003-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.

dkf added on 2003-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.

serhiy.storchaka added on 2026-11-13 11:18:45:

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