TIP 315: Add pathSeparator to tcl_platform Array

Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2017 Conference, Houston/TX, US, Oct 16-20
Send your abstracts to tclconference@googlegroups.com
by Aug 21.
Author:		Hai Vu <haivu2004@gmail.com>
State:		Final
Type:		Project
Tcl-Version:	8.6
Vote:		Done
Created:	04-Apr-2008
Post-History:	

Abstract

This TIP proposes a mechanism for determining the platform's path separator. The path separator is currently ":" in Unix and ";" in DOS/Windows.

Rationale

Under Windows, the PATH environment variable consists of many paths, separated by semicolons (";"). Meanwhile, Unix uses colon to separate the paths (":"). Scripts that need to work on both platforms while parsing platform-specific PATH-like environment variables (PATH is just the most common of these) currently need to contain the mapping from platform-type to separator, but this is not especially flexible and some script authors are also inclined to forget about this particular difference.

Thus, to aid portability, this TIP proposes adding an element to the tcl_platform array, pathSeparator, which describes the path separator for the current platform.

Example Usage

The following example prints each component of the PATH environment on a separate line:

set pathList [split $env(PATH) $tcl_platform(pathSeparator)]
foreach path $pathList {
    puts $pathList
}

Alternatively:

puts [string map [list $tcl_platform(pathSeparator) \n] $env(PATH)]

Copyright

This document has been placed in the public domain.

History