| |||||||||||
| |||||||||||
Splitting the difference
Perl's split function takes a string of text, and divides it up at a delimiter of your choice into a list of shorter strings ... it's one of the "power tool" functions of Perl and a vital part of the language. So how come that you can write a Tcl program and use its version of split - or omit the split command - and it seems to work either way. Does that seem odd
In Tcl, the split function also turns a string into a list ... it's just that a Tcl list is a string that's formatted with an unprotected space between each list element, which is probably where you started from the in the first place. In other words, the reason you can often include or leave out the call is because in Tcl's case it often does nothing at all!! Python has two split methods - one that uses an explicit string as the delimiter on which it's to split, and the other in its regular expression class that makes it much more closely akin to the Perl flavour, and in PHP the split function splits at a literal string (you should use preg_split or explode in PHP to split at a regular expression). Do you ever wonder why I only teach one language per day? (written 2005-10-13 06:57:59) Associated topics are indexed under T206 - Tcl/Tk - ListsP208 - Perl - Lists H107 - String Handling in PHP Y108 - Python - String Handling Y115 - Additional Python Facilities
Some other Articles
Tell them three timesSeparating 'per instance' data from binaries and web sites Changing Tomcat's web.xml and reloading a web application Technical Loneliness Splitting the difference Big number Shortened interactive commands New Network Kiss and Ride Final courses of '05 coming up .... 1705 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35 at 50 posts per pageThis is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price. Link to Ezine home page (for reading). Link to Blogging home page (to add comments). |
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho | |||||||||||