[ic] IF & ELSIF's made easy? Not for me :-)
interchange-users@icdevgroup.org
interchange-users@icdevgroup.org
Tue Jul 23 11:39:01 2002
On Tue, Jul 23, 2002 at 08:15:26AM -0700, Barry Treahy, Jr. wrote:
> 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:
I was going to say, just do it in perl. Remember that the tags are
what make ic useful to **non-programmers**. If you are good at
perl, use perl. For years now we've not used tags for anything much fancier
than [order]foo</A>.
If you are concerned about efficiency, put the code into a module
or tag and force precompilation.
>
> [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
>
>
> _______________________________________________
> interchange-users mailing list
> interchange-users@icdevgroup.org
> http://www.icdevgroup.org/mailman/listinfo/interchange-users
>
--
Christopher F. Miller, Publisher cfm@maine.com
MaineStreet Communications, Inc 208 Portland Road, Gray, ME 04039
1.207.657.5078 http://www.maine.com/
Content/site management, online commerce, internet integration, Debian linux