Skeeve has asked for the wisdom of the Perl Monks concerning the following question:

Hello fellow monks!

Update 2:Forget about the question... The problem was not the SWITCH directive but the "$report_type" instead of "report_type"...

Recently I switched to Template Toolkit 2 for creating XML from spreadsheet data. Today I noticed that the SWITCH directive didn't work as I expected. I wrote

SWITCH $report_type
CASE [ "SYSTEM" "DATACENTER" ];

This didn't work because the correct syntax is

SWITCH $report_type
CASE [ SYSTEM DATACENTER ];

So now I'm wondering what the correct way it might be, hadn't I "DATACENTER" but "DATA CENTER"...

Does anyone of you know a solution?

UPDATE: I just noticed that the statement above is wrong and I have absolutely no clue how to correctly write a SWITCH directive :-(


s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Replies are listed 'Best First'.
Re: TT2 SWITCH - how to do it
by Anonymous Monk on Jan 16, 2006 at 21:16 UTC
    I believe you need to add square brackets to show LIST of values. Please see example from TT doc below ...

    SWITCH / CASE

    The SWITCH / CASE construct can be used to perform a multi-way conditional test. The SWITCH directive expects an expression which is first evaluated and then compared against each CASE statement in turn. Each CASE directive should contain a single value or a list of values which should match. CASE may also be left blank or written as [% CASE DEFAULT %] to specify a default match. Only one CASE matches, there is no drop-through between CASE statements.

    [% SWITCH myvar %] [% CASE value1 %] ... ===>[% CASE [ value2 value3 ] %] # multiple values ... [% CASE myhash.keys %] # ditto ... [% CASE %] # default ... [% END %]
    See: TT Directives: Conditional Processing