TIP #358: Suppress Empty List Element Generation from the Split Command


TIP:358
Title:Suppress Empty List Element Generation from the Split Command
Version:$Revision: 1.2 $
Author:George Petasis <petasis at iit dot demokritos dot gr>
State:Draft
Type:Project
Tcl-Version:8.7
Vote:Pending
Created:Sunday, 04 October 2009
Keywords:Tcl, list extraction, parsing

Abstract

The split command will create empty list elements when adjacent split characters are found in the input. In some cases these empty list elements are not desired, so this TIP proposes a new switch to disable their generation.

Rationale

The idea for this TIP came from a discussion in comp.lang.tcl: [1] and the (non obvious) suggestions on how tokens can be extracted from a string can be performed efficiently.

It should be noted that this will allow the split command to be used in a fashion that is very similar to how splitting works in many other languages (e.g., Perl, awk, Unix shells).

Specification

This TIP proposes a new optional switch (-noemptyelements) to the split command:

split -noemptyelements string ?splitChars?

If this option is present, then split will not produce an empty list element when the string contains adjacent characters that are present in splitChars.

Reference Implementation

Currently there is no patch, but it should be quite easy to implement this.

Copyright

This document has been placed in the public domain.


Powered by Tcl[Index] [History] [Edit] [HTML Format] [Source Format] [LaTeX Format] [Text Format] [XML Format] [*roff Format (experimental)] [RTF Format (experimental)]

TIP AutoGenerator - written by Donal K. Fellows