473,883 Members | 1,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do you convert a TCL list into a string that PHP can read?

I have a TCL proc that needs to convert what might be a list into a
string to read

consider this:

[set string [PROPER_CASE {hello world}]]; # OUTPUTS Hello World which
is fine for PHP

[set string [PROPER_CASE {-hello world}]]; # OUTPUT {{-Hello}}
World, which PHP will print literally as {{-Hello}} World, instead of
-Hello World

Is there an easy way for TCL to brute-force a list into a
strictly-string-only format to prevent this potentially ugly display
from being displayed by PHP/etc.?

Thanx
Phil

Apr 21 '06
23 9534
Bryan Oakley wrote:
Maybe you should file a bug with whomever wrote PROPER_CASE instead of
trying to work around its limitations.


FWIW, the culprit is this infinite loop:

while {![regexp -nocase {[a-z]} [string index $wordlet $beginIndx]]} {
append nonWord [string index $wordlet $beginIndx]
incr beginIndx
}

Under the right conditions (such as a word beginning or ending with "-"
or "_"), $wordlet will be null. When wordlet is null, [string index
$wordlet $beginIndx] will be null for all values of $beginIndx, the
regexp will never match, and the loop will never terminate.

--
Bryan Oakley
http://www.tclscripting.com
Apr 21 '06 #11
comp.lang.tcl wrote:
Last I checked [string totitle] doesn't capitalize hyphenated names,
Scots/Irish/Dutch names, etc. I wrote it back in 2000, when I only had
about a year's knowledge of TCL at the time, I'm sure it needs a bit of
fine-tuning, but it does the job it's supposed to do.

Phil


It's pretty fragile though. As I pointed out in another message in this
thread, it can get into an infinite loop if a word begins or ends with
"-" or "_". It also will yield unexpected results for other types of
input as well. So, it really only works for a small set of well behaved
inputs.

We can help you with those problems if you like.

Not sure what to do about the OP, other than to suggest perhaps writing
their own PROPER_CASE proc or help to debug this one. There appears to
be no good way to solve his/her problem other than to fix PROPER_CASE.

--
Bryan Oakley
http://www.tclscripting.com
Apr 21 '06 #12

Bryan Oakley wrote:
Bryan Oakley wrote:
Maybe you should file a bug with whomever wrote PROPER_CASE instead of
trying to work around its limitations.

FWIW, the culprit is this infinite loop:

while {![regexp -nocase {[a-z]} [string index $wordlet $beginIndx]]} {
append nonWord [string index $wordlet $beginIndx]
incr beginIndx
}


WOW! I would never have found that one, you are truly one of the TCL
gurus out there (you came highly recommended by those I know)

this seemed to have fixed the problem (probably overkill but it was the
best I could think up at the moment:

while {[info exists wordlet] && [string length $wordlet] > 0 &&
![regexp -nocase {[a-z]} [string index $wordlet $beginIndx]]} {
append nonWord [string index $wordlet $beginIndx]
incr beginIndx
}

Phil

Under the right conditions (such as a word beginning or ending with "-"
or "_"), $wordlet will be null. When wordlet is null, [string index
$wordlet $beginIndx] will be null for all values of $beginIndx, the
regexp will never match, and the loop will never terminate.

--
Bryan Oakley
http://www.tclscripting.com


Apr 21 '06 #13
comp.lang.tcl wrote:

WOW! I would never have found that one, you are truly one of the TCL
gurus out there (you came highly recommended by those I know)
Thanks for the compliment but finding it took two minutes. I simply put
a print statement at the top of every loop, then tried a couple of very
obvious tests.
this seemed to have fixed the problem (probably overkill but it was the
best I could think up at the moment:

while {[info exists wordlet] && [string length $wordlet] > 0 &&
![regexp -nocase {[a-z]} [string index $wordlet $beginIndx]]} {
append nonWord [string index $wordlet $beginIndx]
incr beginIndx
}


Yeah, that definitely helps that particular problem but it doesn't fix
all problems in the code.

Since you seem new to programming, you might want to look at tcltest.
Once you are up to speed on it (which doesn't take long), it would take
about 5-10 minutes to craft a couple dozen tests to validate the proc
against a whole range of inputs. That would have uncovered many bugs.

http://mini.net/tcl/tcltest
--
Bryan Oakley
http://www.tclscripting.com
Apr 21 '06 #14
comp.lang.tcl wrote:
Gerald W. Lester wrote:
Bryan Oakley wrote:
comp.lang.tcl wrote:
> Sorry, there is no further description I can give you. tclsh locks,
> produces 100% CPU usage when you view via top, no error logs of any
> kind.
>
> Here is PROPER_CASE:
> <snip>

Holy cow! All that just to change the case of words in a string?

The proc is a bit buggy at first glance. It's amazing it works at all.
It takes a string, does some string operations on it, then iterates over
it as if it were a list and performs list operations on it. Then, it
takes the list, performs string operations on it and returns a string.

Indeed, testing it out by copying it into a tclsh session, it _is_
buggy. If the first char is "-" it gets in an infinite loop.

Maybe you should file a bug with whomever wrote PROPER_CASE instead of
trying to work around its limitations.


It does a *little* more than [string totitle $string] -- it ignores two
letter state "names" -- but not much.


Last I checked [string totitle] doesn't capitalize hyphenated names,
Scots/Irish/Dutch names, etc. I wrote it back in 2000, when I only had
about a year's knowledge of TCL at the time, I'm sure it needs a bit of
fine-tuning, but it does the job it's supposed to do.


You should factor out some of the code in there. Not because it is
faster, or to make the code re-usable or even to save memory but simply
to make it easier to understand. Here's a work-alike version I whipped
up in about 2 minutes:

######
# Reformats a string to have proper case
######
proc properCase {str} {
set ret ""
foreach x [split $str " \t\n\r"] {
append ret "[caseFormat [string trim $x]]"
append ret " "
}
return $ret
}

########
# Applies case formatting rule to a word
########
proc caseFormat {word} {
if {[set ret [irishScotFormat $word]] != ""} {
return $ret
}
if {[set ret [smallWordFormat $word]] != ""} {
return $ret
}
if {[set ret [statesFormat $word]] != ""} {
return $ret
}
return [string totitle $word [firstAlpha $word] end]
}

# Returns first alpha char in a word
proc firstAlpha {word} {
for {set i 0} {$i < [string length $word]} {incr i} {
if {[string is alpha [string index $word $i]]} {
return $i
}
}
return end
}

############### # Formatting rules:

proc smallWordFormat {word} {
if {[lsearch -exact {
a an in of and at is
} $word] != -1} {
return $word
}
return ""
}

proc irishScotFormat {word} {
return ""
}

proc statesFormat {word} {
set word [string toupper $word]
if {[lsearch -exact {
AL AK AR AZ CA CO CT DE DC FL GA
HI ID IL IN IA KS KY LA ME MD MA
MI MN MS MO MT NE NV NH NJ NM NY
NC ND OH OK OR PA RI SC SD TN TX
UT VT VA WA WV WI WY PR GU VI NE
NW SE SW N.E. S.E. S.W. N.W.
} $word] != -1} {
return $word
}
return ""
}
I haven't implemented the irishScotFormat proc partly because I'm not
sure what you want and partly because I'm too lazy to do it. Notice
that the bulk of the processing happens in caseFormat which only have
to handle a single word at a time. This simplifies the properCase proc
to simply parse the string a word at a time without having to worry
about the processing. It's also very easy to add in more formatting
checks in the caseFormat proc.

Hope this helps you a little, I just had to re-implement it, the
[PROPER_CASE] proc was too ugly for me to resist.

Apr 21 '06 #15
sl*******@yahoo .com wrote:
comp.lang.tcl wrote:
Gerald W. Lester wrote:
Bryan Oakley wrote:
> comp.lang.tcl wrote:
>> Sorry, there is no further description I can give you. tclsh locks,
>> produces 100% CPU usage when you view via top, no error logs of any
>> kind.
>>
>> Here is PROPER_CASE:
>> <snip>
>

It does a *little* more than [string totitle $string] -- it ignores two
letter state "names" -- but not much.


Last I checked [string totitle] doesn't capitalize hyphenated names,
Scots/Irish/Dutch names, etc.


Oops, forgot about another thing the original code did. Add this rule
to the code I previously submitted:

proc uppercaseFormat {word} {
if {[string toupper $word] == $word} {return $word}
return ""
}

Apr 21 '06 #16

Bryan Oakley wrote:
comp.lang.tcl wrote:

WOW! I would never have found that one, you are truly one of the TCL
gurus out there (you came highly recommended by those I know)
Thanks for the compliment but finding it took two minutes. I simply put
a print statement at the top of every loop, then tried a couple of very
obvious tests.


Right, I do the same with PHP, using print_r() everywhere I go, but I
don't know how to do that with TCL especially in the environment I have
here at work (RHEL4)
this seemed to have fixed the problem (probably overkill but it was the
best I could think up at the moment:

while {[info exists wordlet] && [string length $wordlet] > 0 &&
![regexp -nocase {[a-z]} [string index $wordlet $beginIndx]]} {
append nonWord [string index $wordlet $beginIndx]
incr beginIndx
}


Yeah, that definitely helps that particular problem but it doesn't fix
all problems in the code.

Since you seem new to programming,


Sorry, I'm not new, I've been at it since 1996. Web programming that
is. Done TCL since 1999. I just don't have the means of testing my
TCL procs apart from using Wish on my very slow home PC (I use Linux at
work, haven't yet found an environment I can use to test TCL procs at
work and don't have root access to my machine even if I were to find
something).

you might want to look at tcltest. Once you are up to speed on it (which doesn't take long), it would take
about 5-10 minutes to craft a couple dozen tests to validate the proc
against a whole range of inputs. That would have uncovered many bugs.

http://mini.net/tcl/tcltest
--
Bryan Oakley
http://www.tclscripting.com


Apr 21 '06 #17
comp.lang.tcl wrote:
Sorry, I'm not new, I've been at it since 1996. Web programming that
is. Done TCL since 1999. I just don't have the means of testing my
TCL procs apart from using Wish on my very slow home PC (I use Linux at
work, haven't yet found an environment I can use to test TCL procs at
work and don't have root access to my machine even if I were to find
something).


That's an odd statement. If you have the ability to edit and run them,
you can test them. tcltest is 100% pure tcl. In fact, if you can run
them via your web server, you can run tests *in* your webserver. Just
drop the tcltest source code wherever you can access it (read: in the
same file or directory where PROPER_CASE is defined) and off you go. Of
course, you can also test them via tclsh if you have that available.

As for testing them at home, I bet even the slowest PC you can find that
is still running is sufficient to run tcltest for a modest number of tests.

I don't mean to be telling you how to work. It's just that these errors
were so trivial to reproduce that it seemed like a beginners mistake. No
offense. I just didn't think you were aware of some of the options
available to you.

--
Bryan Oakley
http://www.tclscripting.com
Apr 21 '06 #18
MH
In article <11************ **********@u72g 2000cwu.googleg roups.com>,
comp.lang.tcl <ph************ **@gmail.com> wrote:

Bryan Oakley wrote:
comp.lang.tcl wrote:
>
> WOW! I would never have found that one, you are truly one of the TCL
> gurus out there (you came highly recommended by those I know)
Thanks for the compliment but finding it took two minutes. I simply put
a print statement at the top of every loop, then tried a couple of very
obvious tests.


Right, I do the same with PHP, using print_r() everywhere I go, but I
don't know how to do that with TCL especially in the environment I have
here at work (RHEL4)


Hmm.. Shouldn't "tclsh" be standard in that environment?

[cut]
Sorry, I'm not new, I've been at it since 1996. Web programming that
is. Done TCL since 1999. I just don't have the means of testing my
TCL procs apart from using Wish on my very slow home PC (I use Linux at
work, haven't yet found an environment I can use to test TCL procs at
work and don't have root access to my machine even if I were to find
something).


I downloaded and compiled tcl on my work machine (even though we use Tcl
extensively and already have several copies of tclsh installed) and intalled
it on my user account. Took all of 30 seconds of configuration to tell it to
install to my home directory, instead of the system directory..

../configure --prefix=/home/mydir/apps
make
make install

MH
Apr 21 '06 #19

MH wrote:
In article <11************ **********@u72g 2000cwu.googleg roups.com>,
comp.lang.tcl <ph************ **@gmail.com> wrote:

Bryan Oakley wrote:
comp.lang.tcl wrote:
>
> WOW! I would never have found that one, you are truly one of the TCL
> gurus out there (you came highly recommended by those I know)

Thanks for the compliment but finding it took two minutes. I simply put
a print statement at the top of every loop, then tried a couple of very
obvious tests.


Right, I do the same with PHP, using print_r() everywhere I go, but I
don't know how to do that with TCL especially in the environment I have
here at work (RHEL4)


Hmm.. Shouldn't "tclsh" be standard in that environment?

[cut]
Sorry, I'm not new, I've been at it since 1996. Web programming that
is. Done TCL since 1999. I just don't have the means of testing my
TCL procs apart from using Wish on my very slow home PC (I use Linux at
work, haven't yet found an environment I can use to test TCL procs at
work and don't have root access to my machine even if I were to find
something).


I downloaded and compiled tcl on my work machine (even though we use Tcl
extensively and already have several copies of tclsh installed) and intalled
it on my user account. Took all of 30 seconds of configuration to tell it to
install to my home directory, instead of the system directory..

./configure --prefix=/home/mydir/apps
make
make install

MH


I have tclsh already on my machine here at work (Linux) so I don't have
to install it.

I read the man pages for tcltest but it's beyond me, sorry. I don't
know how to download it, where to find it (yes did a Google search,
didn't help whatsoever for me), what to do, etc.

I need a "3rd grade" step-by-step instruction to what to do.

Phil

Apr 21 '06 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
18045
by: Andrew V. Romero | last post by:
At work we have an excel file that contains the list of medications and their corresponding strengths. I would like to save the excel file as a text list and paste this list into a javascript function and have JS put this into an array. Then JS would use this array to create a selection list which displays only the names of the drugs. When the user selections one of the drugs, another selection list will be loaded with the avaiable...
1
2477
by: OZ | last post by:
the serproxy claim itself a multi-thread proxy thing. I have sent email to write the original writer and there is no replay after 3 weeks. my configuration and setting are good. http://www.lspace.nildram.co.uk/freeware.html I installed it in rh 9.0 I found it is single user only.
4
9782
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a numeric value according to an arbitrary regular expression.
5
12724
by: XML newbie: Urgent pls help! | last post by:
function to convert string to 1 dimensional array of long in VB.Net
14
10609
by: Web learner | last post by:
In the following code, I want ArrayList object x to be of type double. How can I do that? --Thanks SqlConnection objConnection = new SqlConnection("server=(local)\\SQLEXPRESS; database=Northwind; integrated security=true;"); String strSQL = "SELECT ProductName, UnitsInStock FROM Products
5
3797
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public List<RoleData> GetRoles() { return GetRoles(null, false); }
27
5164
by: comp.lang.tcl | last post by:
My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML file into a TCL list as follows: attr1 {val1} attr2 {val2} ... attrN {valN} This is the TCL code that does this: set contents ]; close $fileID
1
6094
by: pnbaocuong | last post by:
Dear All When I try to use convert function of MS sql server like this: String sql = " (employee_id = '" + employee_id + "') and ((convert(VARCHAR,w_date,103) = '" + w_date + "'))"; PAYROLLDataSet.WORKINGTIMESRow workingtime_row = (PAYROLLDataSet.WORKINGTIMESRow)pAYROLLDataSet.WORKINGTIMES.Select(sql); Whe I run, it rais bellow exception:
0
10799
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information inside an image, hide your complete image as text ,search for a particular image inside a directory, minimize the size of the image. However this is not a new concept, there is a concept called Steganography which enables to conceal your secret...
0
9777
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11109
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10726
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10833
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9558
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7114
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4602
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3226
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.