🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: bit.listserv.script-l
1 messages
1 total messages Started by Mark C. Lawrence Wed, 02 Mar 1994 18:48
Re: How to test a variable
#401
Author: Mark C. Lawrence
Date: Wed, 02 Mar 1994 18:48
105 lines
4311 bytes
REPLY TO 03/01/94 21:33 FROM SCRIPT-L@UGA.BITNET "IBM vs Waterloo SCRIPT
discussion group": How to test a variable

Benjamin Chi <BEC@ALBANY.EDU> writes,

>I have a situation where if variable x contains the string "XXX" I want
>one thing to happen; if it contains anything else (say, "YYY ZZZ") I want
>something else to happen.  How do I perform this test?
>
>.se x = 'XXX'
>.if &x = XXX;.th FOO;.el BAR
>.if XXX = &x;.th FOO;.el BAR
>
>gives  FOO BAR  when processed by SCRIPT; I should think it would give
>FOO FOO .  If I replace the first statement with
>
>.se x = 'YYY ZZZ'
>
>then I get the diagnostic statement
>INVALID KEYWORD FOR CONDITION ON .IF.
>'TRY' LINE 3: .if YYY ZZZ = XXX;.th FOO;.el BAR
>(which I understand), and still  FOO BAR .
>
>Questions:
>(1) Why aren't the two .if statements in either of the two examples
>entirely equivalent?
>(1a) Why didn't I get the same diagnostic for line 2 of the second
>example?
>(2) What is the syntactically correct way to test the contents of a
>variable whose value may be a string with embedded spaces?

There are two problems.  First, if the string to be compared may include
blanks, then you need to enclose it in delimiters (such as quotes) on the .IF
statement.  Second, &x is the name of a built-in function (hex to string) so
can be ambiguous.  I did some tests with "input trace" turned on:

.se x = 'XXX'
.if &x = XXX;.th FOO;.el BAR
.if XXX = &x;.th FOO;.el BAR

.it all on
.se x = 'YYY ZZZ'

.if '&x' = 'XXX';.th FOO;.el BAR
.sk 2
.if 'XXX' = '&x';.th FOO;.el BAR
==============output================================

FOO FOO                            <= as expected
BAR                                <= also as expected
th FOO;.el BAR                     <= after error, following
                                      stuff treated as text
==============trace=================================
00000008                    .if '&x' = 'XXX';.th FOO;.el BAR
*S*                         .if 'YYY ZZZ' = 'XXX';.th FOO;.el BAR
00000010                    .if 'XXX' = '&x';.th FOO;.el BAR
*S*                         .if 'XXX' = ';th FOO;.el BAR
*T*                         .if 'XXX' = '
SCRW015E  MISMATCHED DELIMITER ON STRING.
ERROR OCCURRED AT LINE 00000010 OF FILE SYSIN:

But the following works.  I added a period after "x" to delimit the symbol.

 .if 'XXX' = '
             *
.se x = 'XXX'
.if &x = XXX;.th FOO;.el BAR
.if XXX = &x;.th FOO;.el BAR

.it all on
.se x = 'YYY ZZZ'

.if '&x' = 'XXX';.th FOO;.el BAR
.sk 2
.if 'XXX' = '&x.';.th FOO;.el BAR
==============output====================================

FOO FOO
BAR
BAR
==============trace=================================
00000008                    .if '&x' = 'XXX';.th FOO;.el BAR
*S*                         .if 'YYY ZZZ' = 'XXX';.th FOO;.el BAR
00000010                    .if 'XXX' = '&x.';.th FOO;.el BAR
*S*                         .if 'XXX' = 'YYY ZZZ';.th FOO;.el BAR

If you use a symbol name that can't be mistaken for the name of a built-in
function, this also fixes it:

.se mm = 'YYY ZZZ'

.if '&mm' = 'XXX';.th FOO;.el BAR
.if 'XXX' = '&mm';.th FOO;.el BAR
==============output====================================

BAR BAR


========================================================
Mark C. Lawrence
Systems Programmer     Internet: M.Lawrence@Forsythe.Stanford.edu
Stanford Data Center     Bitnet: M.Lawrence@STANFORD
Stanford, CA 94305-4136     Tel: (415) 723-4976

To:  SCRIPT-L@UGA.BITNET
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads