Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

(null cookie; hope that's ok)


devel / comp.lang.tcl / Re: regexp problem

SubjectAuthor
* regexp problemKenny McCormack
+* Re: regexp problemHarald Oehlmann
|`* Re: regexp problemKenny McCormack
| `* Re: regexp problemRalf Fassel
|  `* Re: regexp problemKenny McCormack
|   `* Re: regexp problemLuc
|    `* Re: regexp problemHarald Oehlmann
|     `* Re: regexp problemet99
|      `- Re: regexp problemLuc
`* Re: regexp problemLuc
 +* Re: regexp problemet99
 |`* Re: regexp problemRich
 | `* Re: regexp problemet99
 |  `* Re: regexp problemKenny McCormack
 |   `* Re: regexp problemRich
 |    `- Re: regexp problemet99
 `- Re: regexp problemKenny McCormack

1
regexp problem

<uq272m$126b5$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12922&group=comp.lang.tcl#12922

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.tcl
Subject: regexp problem
Date: Thu, 8 Feb 2024 09:32:06 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <uq272m$126b5$1@news.xmission.com>
Injection-Date: Thu, 8 Feb 2024 09:32:06 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1120613"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Thu, 8 Feb 2024 09:32 UTC

For some reason, when I use "regexp -inline" and try to capture the output,
it fails. Observe:

First, run expect, capture the output - which is the digit string (this works):
expect 1.8> regexp -inline \[0-9]+ [time {sleep 5}]
Result: 5000267

Now, try to capture that result in variable foo:
expect 1.9> set foo [regexp -inline \[0-9]+ [time {sleep 5}]]
Error: wrong # args: should be "regexp ?-option ...? exp string ?matchVar? ?subMatchVar ...?"

Now, try to do the same thing, using lindex, but get same result:
expect 1.11> puts "Time: [lindex [regexp -inline \[0-9]+ [time {sleep 5}]] 0]"
Error: wrong # args: should be "regexp ?-option ...? exp string ?matchVar? ?subMatchVar ...?"

Why?

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/RoyDeLoon

Re: regexp problem

<uq2gmt$1v2vf$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12924&group=comp.lang.tcl#12924

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wortka...@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: regexp problem
Date: Thu, 8 Feb 2024 13:16:30 +0100
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <uq2gmt$1v2vf$1@dont-email.me>
References: <uq272m$126b5$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 8 Feb 2024 12:16:30 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="644730e6d735cb59fd5fc628c0ada679";
logging-data="2067439"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18YXboB9cpfOdlJOAh71rpa"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:yTojBcW7/nBh6Dp+XS9UmzI58Kc=
In-Reply-To: <uq272m$126b5$1@news.xmission.com>
Content-Language: en-GB
 by: Harald Oehlmann - Thu, 8 Feb 2024 12:16 UTC

Am 08.02.2024 um 10:32 schrieb Kenny McCormack:
> For some reason, when I use "regexp -inline" and try to capture the output,
> it fails. Observe:
>
> First, run expect, capture the output - which is the digit string (this works):
> expect 1.8> regexp -inline \[0-9]+ [time {sleep 5}]
> Result: 5000267
>
> Now, try to capture that result in variable foo:
> expect 1.9> set foo [regexp -inline \[0-9]+ [time {sleep 5}]]
> Error: wrong # args: should be "regexp ?-option ...? exp string ?matchVar? ?subMatchVar ...?"
>
> Now, try to do the same thing, using lindex, but get same result:
> expect 1.11> puts "Time: [lindex [regexp -inline \[0-9]+ [time {sleep 5}]] 0]"
> Error: wrong # args: should be "regexp ?-option ...? exp string ?matchVar? ?subMatchVar ...?"
>
> Why?
>

Try:

set foo [regexp -inline {[0-9]+} [time {sleep 5}]]

or

set foo [regexp -inline \[0-9\]+ [time {sleep 5}]]

You close the opening "[" with the RE. This does not play any role, if
you don't open a "[".

Harald

Re: regexp problem

<uq2lao$12bth$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12927&group=comp.lang.tcl#12927

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!newsfeed.endofthelinebbs.com!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.tcl
Subject: Re: regexp problem
Date: Thu, 8 Feb 2024 13:35:20 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <uq2lao$12bth$1@news.xmission.com>
References: <uq272m$126b5$1@news.xmission.com> <uq2gmt$1v2vf$1@dont-email.me>
Injection-Date: Thu, 8 Feb 2024 13:35:20 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1126321"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Thu, 8 Feb 2024 13:35 UTC

In article <uq2gmt$1v2vf$1@dont-email.me>,
Harald Oehlmann <wortkarg3@yahoo.com> wrote:
....
>> Why?
>>
>
>Try:
>
>set foo [regexp -inline {[0-9]+} [time {sleep 5}]]
>
>or
>
>set foo [regexp -inline \[0-9\]+ [time {sleep 5}]]
>
>You close the opening "[" with the RE. This does not play any role, if
>you don't open a "[".

I'm actually more interested in "why", than in alternatives.
(But note: Yes, both of your alternatives do work)

So, maybe an insight as to why?
The point is why does it work OK when you just print the result, but fails
when you wrap it inside a "set" to capture the result?

I suppose it is an instance of a common/general problem with TCL - that it
encourages "slop" - coding that isn't correct, but usually works. I've
gotten into the habit - with all kinds of Unix "regular expression"-using
programs - that you only have to escape the first [ (and not the closing ])
because if the first one is escaped, then the second one is sort of
'auto-escaped'. You'd be surprised how often this works OK (even though, I
suppose, it shouldn't).

This kind of "slop" is why some people say disparaging things about TCL as
a programming language. Well, one of the common reasons; there are others.
I'm not really a TCL programmer (I just fake it), but I've been programming
Expect for decades now.

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/Rorschach

Re: regexp problem

<ygasf23m59g.fsf@panther.akutech-local.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12928&group=comp.lang.tcl#12928

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralf...@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: regexp problem
Date: Thu, 08 Feb 2024 14:53:31 +0100
Lines: 43
Message-ID: <ygasf23m59g.fsf@panther.akutech-local.de>
References: <uq272m$126b5$1@news.xmission.com> <uq2gmt$1v2vf$1@dont-email.me>
<uq2lao$12bth$1@news.xmission.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net ofqnTEtFux6VWe7RZ4rz6wnZM8NyQPtVskV1M+eDFZ0YDf5/g=
Cancel-Lock: sha1:usYepNU3tzakCg0ZuTXIoOrdHaQ= sha1:s2cNr204g4Pj5HsfPynUUorNjTU= sha256:sU6UHDYvzk/+/Nyjf5AHJ6Kfje3l5Ow0tNF/oOE0ODs=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
 by: Ralf Fassel - Thu, 8 Feb 2024 13:53 UTC

* gazelle@shell.xmission.com (Kenny McCormack)
| >set foo [regexp -inline {[0-9]+} [time {sleep 5}]]
| >
| >or
| >
| >set foo [regexp -inline \[0-9\]+ [time {sleep 5}]]
| >
| >You close the opening "[" with the RE. This does not play any role, if
| >you don't open a "[".
>
| I'm actually more interested in "why", than in alternatives.
| (But note: Yes, both of your alternatives do work)
>
| So, maybe an insight as to why?
>
| The point is why does it work OK when you just print the result, but fails
| when you wrap it inside a "set" to capture the result?

The point is not the 'set' itself, but the additional pair of [].

In
regexp -inline \[0-9]+ [time {sleep 5}]

the closing "]" is not matched by an opening "[", so TCL just 'uses' it,
as in

set x ]

However, in

set x [regexp -inline \[0-9]+ [time {sleep 5}]]

The "]" after the '9' closes the opening "[" of the 'set' command, so
regexp is actually called with

regexp -inline \[0-9

which is clearly not enough arguments :-). (Note that if it were to
succeed, then 'set' would complain about too many arguments
(the "+ [time {sleep 5}]]")

HTH
R'

Re: regexp problem

<uq2si1$12nf1$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12929&group=comp.lang.tcl#12929

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.tcl
Subject: Re: regexp problem
Date: Thu, 8 Feb 2024 15:38:41 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <uq2si1$12nf1$1@news.xmission.com>
References: <uq272m$126b5$1@news.xmission.com> <uq2gmt$1v2vf$1@dont-email.me> <uq2lao$12bth$1@news.xmission.com> <ygasf23m59g.fsf@panther.akutech-local.de>
Injection-Date: Thu, 8 Feb 2024 15:38:41 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1138145"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Thu, 8 Feb 2024 15:38 UTC

In article <ygasf23m59g.fsf@panther.akutech-local.de>,
Ralf Fassel <ralfixx@gmx.de> wrote:
....
>The point is not the 'set' itself, but the additional pair of [].
>
>In
> regexp -inline \[0-9]+ [time {sleep 5}]
>
>the closing "]" is not matched by an opening "[", so TCL just 'uses' it,
>as in
>
> set x ]
>
>However, in
>
> set x [regexp -inline \[0-9]+ [time {sleep 5}]]
>
>The "]" after the '9' closes the opening "[" of the 'set' command, so
>regexp is actually called with
>
> regexp -inline \[0-9
>
>which is clearly not enough arguments :-). (Note that if it were to
>succeed, then 'set' would complain about too many arguments
>(the "+ [time {sleep 5}]]")

Yes, interesting. Thanks.

I guess the moral is: Don't be sloppy!

--
"They say if you play a Microsoft CD backwards, you hear satanic messages.
Thats nothing, cause if you play it forwards, it installs Windows."

Re: regexp problem

<20240208133532.406c0346@lud1.home>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12930&group=comp.lang.tcl#12930

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: luc...@sep.invalid (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: regexp problem
Date: Thu, 8 Feb 2024 13:35:32 -0300
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <20240208133532.406c0346@lud1.home>
References: <uq272m$126b5$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="7e194c6486869efde7c293a8560f6f6b";
logging-data="2156967"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19F0lFPJRl4YyzXsN86RhTMcmt7sHIjguo="
Cancel-Lock: sha1:h2m9D3uWLvOo5KjAZZgIzvIqh+Q=
 by: Luc - Thu, 8 Feb 2024 16:35 UTC

On Thu, 8 Feb 2024 09:32:06 -0000 (UTC), Kenny McCormack wrote:

>For some reason, when I use "regexp -inline" and try to capture the output,
>it fails. Observe:
>
>First, run expect, capture the output - which is the digit string (this
>works):
> expect 1.8> regexp -inline \[0-9]+ [time {sleep 5}]
> Result: 5000267
>
>Now, try to capture that result in variable foo:
> expect 1.9> set foo [regexp -inline \[0-9]+ [time {sleep 5}]]
> Error: wrong # args: should be "regexp ?-option ...? exp
> string ?matchVar? ?subMatchVar ...?"
>
>Now, try to do the same thing, using lindex, but get same result:
>expect 1.11> puts "Time: [lindex [regexp -inline \[0-9]+ [time {sleep 5}]]
>0]" Error: wrong # args: should be "regexp ?-option ...? exp
>string ?matchVar? ?subMatchVar ...?"
>
>Why?
**************************

I don't know what the output of [time {sleep 5}] is. Can you please
provide some string I can work on? I would like to make a few tests.

--
Luc
>>

Re: regexp problem

<uq3gmn$24q7i$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12935&group=comp.lang.tcl#12935

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et9...@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: regexp problem
Date: Thu, 8 Feb 2024 13:22:31 -0800
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <uq3gmn$24q7i$1@dont-email.me>
References: <uq272m$126b5$1@news.xmission.com>
<20240208133532.406c0346@lud1.home>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 8 Feb 2024 21:22:31 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ae3d1b79eafe4fc8ca5097c126a63a15";
logging-data="2255090"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/x9994H11fCaXV/nxOxjGW"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:YAXIY29lMMKUbKSjxIxio5KNHk8=
Content-Language: en-US
In-Reply-To: <20240208133532.406c0346@lud1.home>
 by: et99 - Thu, 8 Feb 2024 21:22 UTC

On 2/8/2024 8:35 AM, Luc wrote:
> On Thu, 8 Feb 2024 09:32:06 -0000 (UTC), Kenny McCormack wrote:
>
>> For some reason, when I use "regexp -inline" and try to capture the output,
>> it fails. Observe:
>>
>> First, run expect, capture the output - which is the digit string (this
>> works):
>> expect 1.8> regexp -inline \[0-9]+ [time {sleep 5}]
>> Result: 5000267
>>
>> Now, try to capture that result in variable foo:
>> expect 1.9> set foo [regexp -inline \[0-9]+ [time {sleep 5}]]
>> Error: wrong # args: should be "regexp ?-option ...? exp
>> string ?matchVar? ?subMatchVar ...?"
>>
>> Now, try to do the same thing, using lindex, but get same result:
>> expect 1.11> puts "Time: [lindex [regexp -inline \[0-9]+ [time {sleep 5}]]
>> 0]" Error: wrong # args: should be "regexp ?-option ...? exp
>> string ?matchVar? ?subMatchVar ...?"
>>
>> Why?
> **************************
>
>
> I don't know what the output of [time {sleep 5}] is. Can you please
> provide some string I can work on? I would like to make a few tests.
>
>
Based on his working example, the output is the output of [time] and his [sleep 5] must be 5 seconds. I have a wait proc that does that in ms, so,

% regexp -inline \[0-9\]+ [time {wait 5000}]
5002580
% time {wait 5000}
5012879 microseconds per iteration
%

Re: regexp problem

<uq3iak$252q6$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12936&group=comp.lang.tcl#12936

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.chmurka.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: regexp problem
Date: Thu, 8 Feb 2024 21:50:12 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <uq3iak$252q6$1@dont-email.me>
References: <uq272m$126b5$1@news.xmission.com> <20240208133532.406c0346@lud1.home> <uq3gmn$24q7i$1@dont-email.me>
Injection-Date: Thu, 8 Feb 2024 21:50:12 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0a76cb11b3417798b83a271d819990b2";
logging-data="2263878"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19lkZ1W7lOGnD9CJkuL7kf+"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:YgSDJO1Eiuq04+5CZgmG78WYMrQ=
 by: Rich - Thu, 8 Feb 2024 21:50 UTC

et99 <et99@rocketship1.me> wrote:
> On 2/8/2024 8:35 AM, Luc wrote:
>> On Thu, 8 Feb 2024 09:32:06 -0000 (UTC), Kenny McCormack wrote:
>>
>>> For some reason, when I use "regexp -inline" and try to capture the
>>> output, it fails. Observe:
>>>
>>> First, run expect, capture the output - which is the digit string
>>
>> I don't know what the output of [time {sleep 5}] is. Can you please
>> provide some string I can work on? I would like to make a few
>> tests.
>>
> Based on his working example, the output is the output of [time] and
> his [sleep 5] must be 5 seconds. I have a wait proc that does that
> in ms, so,
>
> % regexp -inline \[0-9\]+ [time {wait 5000}]
> 5002580
> % time {wait 5000}
> 5012879 microseconds per iteration
> %

Kenny's programming Tcl via Expect.

Expect includes a 'sleep' proc as a built in, which works (per the
expect manpage) the same as the Unix/Linux 'sleep' command. The big
difference from Tcl's 'after' is Expect's 'sleep' is documented as
allowing Tk events to be processed while it sleeps.

Re: regexp problem

<uq459p$2etnh$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12937&group=comp.lang.tcl#12937

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et9...@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: regexp problem
Date: Thu, 8 Feb 2024 19:14:00 -0800
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <uq459p$2etnh$1@dont-email.me>
References: <uq272m$126b5$1@news.xmission.com>
<20240208133532.406c0346@lud1.home> <uq3gmn$24q7i$1@dont-email.me>
<uq3iak$252q6$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 9 Feb 2024 03:14:01 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="7589bee22e7d798f42aadcd391d629d2";
logging-data="2586353"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1++IUgT/rdmk0yN2xSmUHgP"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:GhQFPWffMlcXKTgRKOpMVeE/hdA=
In-Reply-To: <uq3iak$252q6$1@dont-email.me>
Content-Language: en-US
 by: et99 - Fri, 9 Feb 2024 03:14 UTC

On 2/8/2024 1:50 PM, Rich wrote:
> et99 <et99@rocketship1.me> wrote:
>> On 2/8/2024 8:35 AM, Luc wrote:
>>> On Thu, 8 Feb 2024 09:32:06 -0000 (UTC), Kenny McCormack wrote:
>>>
>>>> For some reason, when I use "regexp -inline" and try to capture the
>>>> output, it fails. Observe:
>>>>
>>>> First, run expect, capture the output - which is the digit string
>>>
>>> I don't know what the output of [time {sleep 5}] is. Can you please
>>> provide some string I can work on? I would like to make a few
>>> tests.
>>>
>> Based on his working example, the output is the output of [time] and
>> his [sleep 5] must be 5 seconds. I have a wait proc that does that
>> in ms, so,
>>
>> % regexp -inline \[0-9\]+ [time {wait 5000}]
>> 5002580
>> % time {wait 5000}
>> 5012879 microseconds per iteration
>> %
>
> Kenny's programming Tcl via Expect.
>
> Expect includes a 'sleep' proc as a built in, which works (per the
> expect manpage) the same as the Unix/Linux 'sleep' command. The big
> difference from Tcl's 'after' is Expect's 'sleep' is documented as
> allowing Tk events to be processed while it sleeps.

When I capture the microseconds of a time command, I just use [lindex [time ...] 0] rather than a regex. And if you use the repeat count > 1, that value can be a decimal so the regex above would stop before the decimal point.

FWIW, my [wait] proc uses after and vwait with uniquely generated variable names to wait on. So, it can be used at script level or inside events; however, they will be nested, and need to unwind inside-out even if outer timers expire first. But they don't block the event loop, like plain [after].

However, because of that limitation, I've lately turned to using threads with fifo queuing, if I need in-line delays.

Here's my wait, a bit ugly, but it does work as described.

proc wait { ms } {
set uniq [incr ::__sleep__tmp__counter]
set ::__sleep__tmp__$uniq 0
after $ms set ::__sleep__tmp__$uniq 1
vwait ::__sleep__tmp__$uniq
unset ::__sleep__tmp__$uniq
}

Re: regexp problem

<20240209013940.158a0439@lud1.home>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12939&group=comp.lang.tcl#12939

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: luc...@sep.invalid (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: regexp problem
Date: Fri, 9 Feb 2024 01:39:40 -0300
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <20240209013940.158a0439@lud1.home>
References: <uq272m$126b5$1@news.xmission.com>
<uq2gmt$1v2vf$1@dont-email.me>
<uq2lao$12bth$1@news.xmission.com>
<ygasf23m59g.fsf@panther.akutech-local.de>
<uq2si1$12nf1$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="cc075fa77e0fe4886b0148e79ee5fef9";
logging-data="2604995"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/edzqKRWQoLmLiv6hGAwDMjrg+yq3KD+A="
Cancel-Lock: sha1:jwoCTlsRDoMVJqaLYn6GvVGJlKc=
 by: Luc - Fri, 9 Feb 2024 04:39 UTC

On Thu, 8 Feb 2024 15:38:41 -0000 (UTC), Kenny McCormack wrote:

>I guess the moral is: Don't be sloppy!

I no longer remember how but I specifically remember that I once
learned to always enclose regular expressions in curly brackets.
Always. Forget the whole escaping business. Just make sure to
enclose your regular expressions in curly brackets.

And I never had a problem again.

--
Luc
>>

Re: regexp problem

<uq4l4u$2hhpq$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12941&group=comp.lang.tcl#12941

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.nntp4.net!news.hispagatos.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wortka...@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: regexp problem
Date: Fri, 9 Feb 2024 08:44:31 +0100
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <uq4l4u$2hhpq$2@dont-email.me>
References: <uq272m$126b5$1@news.xmission.com> <uq2gmt$1v2vf$1@dont-email.me>
<uq2lao$12bth$1@news.xmission.com> <ygasf23m59g.fsf@panther.akutech-local.de>
<uq2si1$12nf1$1@news.xmission.com> <20240209013940.158a0439@lud1.home>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 9 Feb 2024 07:44:30 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="aaf602e7d68f9fc38d22a9e5cf15e014";
logging-data="2672442"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19TLIzqUMs9jAiA6BccvRpj"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:U3zQrvpXYZKKABFCoXPrRmnBfEA=
In-Reply-To: <20240209013940.158a0439@lud1.home>
Content-Language: en-GB
 by: Harald Oehlmann - Fri, 9 Feb 2024 07:44 UTC

Am 09.02.2024 um 05:39 schrieb Luc:
> On Thu, 8 Feb 2024 15:38:41 -0000 (UTC), Kenny McCormack wrote:
>
>> I guess the moral is: Don't be sloppy!
>
> I no longer remember how but I specifically remember that I once
> learned to always enclose regular expressions in curly brackets.
> Always. Forget the whole escaping business. Just make sure to
> enclose your regular expressions in curly brackets.
>
> And I never had a problem again.
>

+1

Re: regexp problem

<uq4o4o$2i18s$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12942&group=comp.lang.tcl#12942

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et9...@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: regexp problem
Date: Fri, 9 Feb 2024 00:35:35 -0800
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <uq4o4o$2i18s$1@dont-email.me>
References: <uq272m$126b5$1@news.xmission.com> <uq2gmt$1v2vf$1@dont-email.me>
<uq2lao$12bth$1@news.xmission.com> <ygasf23m59g.fsf@panther.akutech-local.de>
<uq2si1$12nf1$1@news.xmission.com> <20240209013940.158a0439@lud1.home>
<uq4l4u$2hhpq$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 9 Feb 2024 08:35:36 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="7589bee22e7d798f42aadcd391d629d2";
logging-data="2688284"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/mRfJDkuO4fJ9k8Um7Nfvr"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:VrqRW7uP3HV26xRikOftqJ4Cb7k=
In-Reply-To: <uq4l4u$2hhpq$2@dont-email.me>
Content-Language: en-US
 by: et99 - Fri, 9 Feb 2024 08:35 UTC

On 2/8/2024 11:44 PM, Harald Oehlmann wrote:
> Am 09.02.2024 um 05:39 schrieb Luc:
>> On Thu, 8 Feb 2024 15:38:41 -0000 (UTC), Kenny McCormack wrote:
>>
>>> I guess the moral is: Don't be sloppy!
>>
>> I no longer remember how but I specifically remember that I once
>> learned to always enclose regular expressions in curly brackets.
>> Always. Forget the whole escaping business. Just make sure to
>> enclose your regular expressions in curly brackets.
>>
>> And I never had a problem again.
>>
>
> +1

I use a tool called regexbuddy4. It's a commercial product, but well worth the small price. The best part is that it can write code and it has templates for 20+ languages, including tcl. Here's a sample, with a comment tree:

# ([0-9]+)
# # Options: Case sensitive; Exact spacing; Dot doesn’t match line breaks; ^$ match at line breaks
# # Match the regex below and capture its match into backreference number 1 «([0-9]+)»
# Match a single character in the range between “0” and “9” «[0-9]+»
# Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»

regexp -linestop -lineanchor {([0-9]+)} $input -> number

I selected "get the part of a string matched by the first capturing group" as the coding goal.

Re: regexp problem

<uq57el$13u0p$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12943&group=comp.lang.tcl#12943

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!newsfeed.endofthelinebbs.com!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.tcl
Subject: Re: regexp problem
Date: Fri, 9 Feb 2024 12:56:53 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <uq57el$13u0p$1@news.xmission.com>
References: <uq272m$126b5$1@news.xmission.com> <uq3gmn$24q7i$1@dont-email.me> <uq3iak$252q6$1@dont-email.me> <uq459p$2etnh$1@dont-email.me>
Injection-Date: Fri, 9 Feb 2024 12:56:53 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1177625"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Fri, 9 Feb 2024 12:56 UTC

In article <uq459p$2etnh$1@dont-email.me>, et99 <et99@rocketship1.me> wrote:
....
>When I capture the microseconds of a time command, I just use [lindex [time ...]
>0] rather than a regex.

Thanks for that. It never occurred to me that I could extract out the
number via "lindex". Six of one, I suppose.

But I still have to push it through "expr" to convert it to seconds (i.e.,
divide it by a million).

--
Which of these is the crazier bit of right wing lunacy?
1) We've just had another mass shooting; now is not the time to be talking about gun control.

2) We've just had a massive hurricane; now is not the time to be talking about climate change.

Re: regexp problem

<uq57he$13u0p$2@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12944&group=comp.lang.tcl#12944

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.tcl
Subject: Re: regexp problem
Date: Fri, 9 Feb 2024 12:58:22 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <uq57he$13u0p$2@news.xmission.com>
References: <uq272m$126b5$1@news.xmission.com> <20240208133532.406c0346@lud1.home>
Injection-Date: Fri, 9 Feb 2024 12:58:22 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1177625"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Fri, 9 Feb 2024 12:58 UTC

In article <20240208133532.406c0346@lud1.home>, Luc <luc@sep.invalid> wrote:
....
>I don't know what the output of [time {sleep 5}] is. Can you please
>provide some string I can work on? I would like to make a few tests.

Yes, as others have noted, "sleep" is a builtin in Expect.

--
On the subject of racism being depicted in the media, the far right and the far left have
met up in agreement (sort of like how plus infinity meets up with minus infinity).
The far left doesn't want it, because they are afraid it will make people racist.
The far right doesn't want it, because they are afraid it will make people feel bad about being racist.

Re: regexp problem

<uq59td$2l9f3$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12945&group=comp.lang.tcl#12945

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: regexp problem
Date: Fri, 9 Feb 2024 13:38:53 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <uq59td$2l9f3$1@dont-email.me>
References: <uq272m$126b5$1@news.xmission.com> <uq3gmn$24q7i$1@dont-email.me> <uq3iak$252q6$1@dont-email.me> <uq459p$2etnh$1@dont-email.me> <uq57el$13u0p$1@news.xmission.com>
Injection-Date: Fri, 9 Feb 2024 13:38:53 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="055b41b1db6ba1f8be9b125d469b1799";
logging-data="2794979"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ojebn5qwvQvMgGYTSyosx"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:nPttZ+lHUc71ieva9NI2aPsUtN8=
 by: Rich - Fri, 9 Feb 2024 13:38 UTC

Kenny McCormack <gazelle@shell.xmission.com> wrote:
> In article <uq459p$2etnh$1@dont-email.me>, et99 <et99@rocketship1.me> wrote:
> ...
>>When I capture the microseconds of a time command, I just use [lindex [time ...]
>>0] rather than a regex.
>
> Thanks for that. It never occurred to me that I could extract out the
> number via "lindex". Six of one, I suppose.

'lindex' will work here (because the output from 'time' is both
consistent and compatible). But be careful applying lindex to any
arbitrary string, doing so can become the source of 'weird' bugs that
only appear months/years later when "just the right string" happens
through.

I.e.:

$ rlwrap tclsh
% set s "string a b { c d e"
string a b { c d e
% lindex $s 0
unmatched open brace in list
%

> But I still have to push it through "expr" to convert it to seconds (i.e.,
> divide it by a million).

True, as it returns microseconds. But that is not too hard to
accomodate if you would prefer not having to write out the division at
every usage:

proc time_s {script {count 1}} {
return [expr {[lindex [time $script $count] 0] / 1000000.0}]
}

% time_s {after 500}
0.500647
%

Or, if you really want to get 'fancy':

rename time ::tcl::time
proc time {script {count 1}} {
return [expr {[lindex [::tcl::time $script $count] 0] / 1000000.0}]
}

% time {after 500}
0.500636
%

Although renaming the real time could mess with any package/modules
that also /might/ use [time]. So be careful with this 'fancy' method.

Re: regexp problem

<uq99h6$4aj6$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12948&group=comp.lang.tcl#12948

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et9...@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: regexp problem
Date: Sat, 10 Feb 2024 17:56:52 -0800
Organization: A noiseless patient Spider
Lines: 71
Message-ID: <uq99h6$4aj6$1@dont-email.me>
References: <uq272m$126b5$1@news.xmission.com> <uq3gmn$24q7i$1@dont-email.me>
<uq3iak$252q6$1@dont-email.me> <uq459p$2etnh$1@dont-email.me>
<uq57el$13u0p$1@news.xmission.com> <uq59td$2l9f3$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 11 Feb 2024 01:56:55 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2486512a0365ac2c910403997298c9d7";
logging-data="141926"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19x97it92VGVF/5HWDkUqmK"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:fujW4TtDW2tST3wPGH4rgi79VmM=
In-Reply-To: <uq59td$2l9f3$1@dont-email.me>
Content-Language: en-US
 by: et99 - Sun, 11 Feb 2024 01:56 UTC

On 2/9/2024 5:38 AM, Rich wrote:
> Kenny McCormack <gazelle@shell.xmission.com> wrote:
>> In article <uq459p$2etnh$1@dont-email.me>, et99 <et99@rocketship1.me> wrote:
>> ...
>>> When I capture the microseconds of a time command, I just use [lindex [time ...]
>>> 0] rather than a regex.
>>
>> Thanks for that. It never occurred to me that I could extract out the
>> number via "lindex". Six of one, I suppose.
>
> 'lindex' will work here (because the output from 'time' is both
> consistent and compatible). But be careful applying lindex to any
> arbitrary string, doing so can become the source of 'weird' bugs that
> only appear months/years later when "just the right string" happens
> through.
>
> I.e.:
>
> $ rlwrap tclsh
> % set s "string a b { c d e"
> string a b { c d e
> % lindex $s 0
> unmatched open brace in list
> %
>
>
>> But I still have to push it through "expr" to convert it to seconds (i.e.,
>> divide it by a million).
>
> True, as it returns microseconds. But that is not too hard to
> accomodate if you would prefer not having to write out the division at
> every usage:
>
> proc time_s {script {count 1}} {
> return [expr {[lindex [time $script $count] 0] / 1000000.0}]
> }
>
> % time_s {after 500}
> 0.500647
> %
>
> Or, if you really want to get 'fancy':
>
> rename time ::tcl::time
> proc time {script {count 1}} {
> return [expr {[lindex [::tcl::time $script $count] 0] / 1000000.0}]
> }
>
> % time {after 500}
> 0.500636
> %
>
> Although renaming the real time could mess with any package/modules
> that also /might/ use [time]. So be careful with this 'fancy' method.

Here's mine, because at 4 in the morning, my eyes need a break and neatness helps.

proc timems {args} {
set result [uplevel 1 time $args]
set number [format %.3f [expr {( [lindex $result 0] / 1000. )}]]
set number [regsub -all {\d(?=(\d{3})+($|\.))} $number {\0,}]
return "[format %12s $number ] milliseconds"
}

% timems {wait 1}
1.042 milliseconds
% timems {wait 5432}
5,432.084 milliseconds
% timems {math::fibonacci 1000000}
49,629.625 milliseconds

Re: regexp problem

<20240212011526.63644675@lud1.home>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=12949&group=comp.lang.tcl#12949

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: luc...@sep.invalid (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: regexp problem
Date: Mon, 12 Feb 2024 01:15:26 -0300
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <20240212011526.63644675@lud1.home>
References: <uq272m$126b5$1@news.xmission.com>
<uq2gmt$1v2vf$1@dont-email.me>
<uq2lao$12bth$1@news.xmission.com>
<ygasf23m59g.fsf@panther.akutech-local.de>
<uq2si1$12nf1$1@news.xmission.com>
<20240209013940.158a0439@lud1.home>
<uq4l4u$2hhpq$2@dont-email.me>
<uq4o4o$2i18s$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="52eff4d5e15132fed71ec6b8b8c69cac";
logging-data="1438165"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19tl35JT1Xwc8LShf6Yim6jOouRrhpE9YA="
Cancel-Lock: sha1:eRt4/YveBtZ9AC6+3Fgq/E6ZKYQ=
 by: Luc - Mon, 12 Feb 2024 04:15 UTC

On Fri, 9 Feb 2024 00:35:35 -0800, et99 wrote:

>I use a tool called regexbuddy4. It's a commercial product, but well worth
>the small price. The best part is that it can write code and it has
>templates for 20+ languages, including tcl.

I've been using Visual Regexp for more than 20 years.

http://laurent.riesterer.free.fr/regexp/

It's written in Tcl and is mostly focused on Tcl, but it's usable for
other situations. I still use it for sed and used it for Perl and PHP
back in the day.

--
Luc
>>

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor