Quote:
Originally Posted by ownedbycats
Thanks  Since both of them use in-progress I was able to reduce it a tiny bit more:
Code:
elif
(status == 'In-Progress' &&
(!select(ids, 'ao3') && $publisher == 'Archive of Our Own')
||
(!select(ids, 'ffnet') && $publisher == 'FanFiction.net')
)
then "metadata.png"
|
You should pay attention to operator precedence and the implied parentheses. The && operator has higher precedence than the || operator, so your statement will evaluate like this:
Code:
program:
if
( status == 'In-Progress' &&
(!select(ids, 'ao3') && $publisher == 'Archive of Our Own')
)
||
(
(!select(ids, 'ffnet') && $publisher == 'FanFiction.net')
)
then "metadata.png"
fi
That isn't what you want because the status == isn't done for the 'ffnet' branch. Instead you want this:
Code:
program:
if status == 'In-Progress' &&
(
(!select(ids, 'ao3') && $publisher == 'Archive of Our Own')
||
(!select(ids, 'ffnet') && $publisher == 'FanFiction.net')
)
then "metadata.png"
fi
By putting the second two checks in parentheses you ensure that the status == check is done for both of them.
My advice: don't depend on operator precedence unless you really know what you are doing. Instead use parentheses to specify the order of evaluation.
EDIT: I forgot to mention: factoring conditions in ifs is a very good thing for performance and readability. It makes the flow clearer and takes maximum advantage of condition short circuiting. Good that you noticed it.