Re: Why do we need "eval"? (Expect question)

Liste des GroupesRevenir à cl tcl 
Sujet : Re: Why do we need "eval"? (Expect question)
De : wortkarg3 (at) *nospam* yahoo.com (Harald Oehlmann)
Groupes : comp.lang.tcl
Date : 12. Sep 2024, 18:33:01
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vbv8kd$blsb$1@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
Am 12.09.2024 um 17:07 schrieb Kenny McCormack:
Consider this (Unix/Linux/bash) command line:
 $ expect -- /dev/fd/3 3<<< 'eval spawn -noecho printf {{\t%s\n}} $argv;interact' $(seq 1 10)
 This correctly generates the output (each line starts with a tab):
  1
2
3
4
5
6
7
8
9
10
 But notice how we have to use "eval" in order to split up the args in $argv.
And, since we are using "eval", we have to "double quote" (with {}) the
"format" arg to "printf".  It'd be nice if neither of these things were
necessary.
 I've always believed that "eval" was "evil" and to be avoided if at all
possible - both in shell and in Tcl.  It has strange side effects, such as
we see here (the need to "double quote").  Is there any way to get the
above effect w/o using "eval" ?
 
Kenny,
thanks for the question. Here is the answer by a TCL'er without expect knowledge.
"eval" does an additional round of substitutions. This happens for all elements and is intended, if a whole command is included in a variable.
To only expand some arguments, the list expansion operator may be used:
In your case:
eval spawn -noecho printf {{\t%s\n}} $argv
equal to:
spawn -noecho printf {\t%s\n} {*}$argv
eventually, this works to:
spawn -noecho printf \t%s\n {*}$argv
Harald

Date Sujet#  Auteur
12 Sep 24 * Why do we need "eval"? (Expect question)11Kenny McCormack
12 Sep 24 `* Re: Why do we need "eval"? (Expect question)10Harald Oehlmann
12 Sep 24  +* Re: Why do we need "eval"? (Expect question)7Kenny McCormack
13 Sep 24  i+* Re: Why do we need "eval"? (Expect question)3Rich
13 Sep 24  ii+- Re: Why do we need "eval"? (Expect question)1Harald Oehlmann
13 Sep 24  ii`- Re: Why do we need "eval"? (Expect question)1Kenny McCormack
13 Sep 24  i`* Re: Why do we need "eval"? (Expect question)3Harald Oehlmann
13 Sep 24  i `* Re: Why do we need "eval"? (Expect question)2Kenny McCormack
13 Sep 24  i  `- Re: Why do we need "eval"? (Expect question)1Rich
13 Sep 24  `* Re: Why do we need "eval"? (Expect question)2Rich
13 Sep 24   `- Re: Why do we need "eval"? (Expect question)1Kenny McCormack

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal