SUBMITTED: Weird if() behavior

Put
if(opexists(“table1”),tab(“table1”,0,0),0)
in a constant CHOP and don’t create the tableDAT “table1”

the constant CHOP complains about non existent table DAT “table1”

But I checked if the table exists, and as it doesn’t it shouldn’t try to get values from it at all.

I ran into similar stuff in scripts, and it seems than touch actually executes all “options”, even if a condition is not met.
Achim

yes, if currently executes all options. will see if we can do something about it…

Selina

here’s my problem loop

set dest = “$arg1”
set field = “$arg2”
set label = argx($field,-1,".")
if ( $label == $field ) then
set label = “”
else
set field = substr($field,0,strlen($field)-strlen($label)-1)
endif

set totparms = `tabrc(“$dest/MAPPER”,“$field”,“NPARMS”)

for cp = 1 to $totparms
set doit = 1
echo A - label $label
if ( strcmp("$label", "") != 0 ) then
set curlabel = tabrc("$dest/MAPPER","$field","L$cp")
echo A.1
if ( strcmp("$label", $curlabel) ) then
set doit = 0
endif
echo A.2
endif
echo B
if ( $doit ) then
table -r “$field” -c “V$cp” $dest/MAPPER “.!”
endif
end

here’s the output when it’s called a few times:

A - label x
A.1
A.2
B
A - label x
A.1
A.2
B
A - label
/GLOBAL/SCRIPTS/CMD/UI_BLOCK_PARM (Line 31) Expression error: Undefined variable
B
A - label
/GLOBAL/SCRIPTS/CMD/UI_BLOCK_PARM (Line 31) Expression error: Undefined variable
B
A - label
/GLOBAL/SCRIPTS/CMD/UI_BLOCK_PARM (Line 31) Expression error: Undefined variable
B
A - label
/GLOBAL/SCRIPTS/CMD/UI_BLOCK_PARM (Line 31) Expression error: Undefined variable
B

you can see how when label is empty, the line:
if ( strcmp("$label", $curlabel) ) then

is still parsed and generates an error, even though it’s inside an if statement that should be skipped (and it is, since no echo A.1 A.2 are happening)

btw, as a possible side bug, I’m using strcmp because the syntax
if ( $label != $curlabel ) then
generates a syntax error.

maybe I’ve done something wrong in the script that I can’t see?
d

Missing quotes around $curlabel? shouldn’t it be if ( strcmp("$label", "$curlabel") ) then?

I run into this a lot. Don’t think it’s a quotes thingy. Like dani says, seems like touch is executing all options in an if() statement. See [url]http://www.derivativeinc.com/forum/viewtopic.php?f=12&t=227[/url] for the same problem in expressions.

It’s annoying, often I have to use a weird workflow, like putting “continue” commands everywhere when mixing for, foreach and if() statements to get rid of those erros. And it’s eating away unnecessary ressources.

Selina sad she’ll take a look at it

I’ve merged the two topics describing the same problem together for clarity in bug tracking.

can you? :laughing:

its pretty messy, I can’t promise a quick solution, but we are looking into it.

Selina

hello, I’ve got a solution to one of the if problems. in the next build, you can use
a parse command
parse -i 1
to turn of parsing for if blocks that are not execute. for now, we are still testing this,
so the default is off. but we may switch it to on sometime.

I haven’t dug too deep at the if expressions if ( $a, 1, 0) and ifs($a, "true", false"),
but will keep you guys posted on my progress.

Selina