[ic] IF & ELSIF's made easy? Not for me :-)
Barry Treahy, Jr.
interchange-users@icdevgroup.org
Tue Jul 23 11:16:00 2002
So many times I have read on this list that the general recommendation
for complex if/else clauses should use explicit/condition combinations,
so I decided to heed that advise. It isn't working as I would expect and
I'm receiving nothing in the logs, so I have to presume that I'm simply
confusing IC. Regardless of the value in body, it always falls to the
ending [ELSE] even though I have confirmed that body contains a valid
content.
[if-item-field body]
<tr>
<td align="left">
Body:
</td>
<td align="right">
[if explicit]
[condition]
$tmp = '[item-field body]';
return 1 if $tmp eq 'STD';
return 0;
[/condition]
Standard
[elsif explicit]
[condition]
$tmp = '[item-field body]';
return 1 if $tmp eq 'FLG';
return 0;
[/condition]
Flange Mounted
[elsif explicit]
[condition]
$tmp = '[item-field body]';
return 1 if $tmp eq 'HEX';
return 0;
[/condition]
Hex
[elsif explicit]
[condition]
$tmp = '[item-field body]';
return 1 if $tmp eq 'SPL';
return 0;
[/condition]
Special Product
[/elsif]
[else]
Unknown Body: [item-field body]
[/else]
[/if]
</td>
</tr>
[/if-item-field]
I then took a different approach, using just Perl code:
[perl]
$tmp = '[item-field body]';
if ($tmp eq 'STD') { return 'Standard'; }
elsif ($tmp eq 'FLG') { return 'Flange Mounted'; }
elsif ($tmp eq 'HEX') { return 'Hex Shaped'; }
elsif ($tmp eq 'SPL') { return 'Special Product'; }
else {
$tmpout = 'Unknown Body: ' + $tmp;
return $tmpout;
}
[/perl]
which worked fine. My question, just for my educational benefit, why
didn't the first work? Second, which of the two would be more efficient
at run time? I personally fine the second much easier on the eyes...
Thanks...
Barry
--
Barry Treahy, Jr * Midwest Microwave * Vice President & CIO
E-mail: Treahy@mmaz.com * Phone: 480/314-1320 * FAX: 480/661-7028