in reply to Conditional statements for template
G'day satya_rockstar,
Welcome to the monastery.
"How do I break the if . I know I cant use a if in a template. How do I break it ?"
I don't know what you mean by "break the if". Templates can have conditionals (as well as other programming constructs): for instance, take a look at Template::Toolkit's syntax. What templating system are you using?
Furthermore, the code you've posted has so many problems, it's difficult to know what you're actually trying to do.
I recommend you first read "perlintro - Perl introduction for beginners" and learn the basic syntax of the language.
Next, "perldsc - Perl data structures intro" will provide information on building, accessing and modifying a complex Perl data structure.
You also need to understand that we can't really help you if you leave out key information or post incomplete and syntactically incorrect code (such as the examples I've already highlighted). Please read "How do I post a question effectively?" for details on this.
Here's my best guess at the type of thing you're trying to achieve:
#!/usr/bin/env perl -l use strict; use warnings; use Data::Dump; my $template = { global => { variables => { variant => 10, dir => 'root', }, }, }; for (qw{s8 s9}) { print "*** Version: $_ ***"; $template->{global}{variables}{version} = $_; if ($template->{global}{variables}{version} eq 's8') { $template->{global}{variables}{base} = "$_/group"; } else { $template->{global}{variables}{base} = "$_/exe/group"; $template->{global}{variables}{exe} = 'exe_state'; } dd $template; }
Output:
*** Version: s8 *** { global => { variables => { base => "s8/group", dir => "root", variant => 10, v +ersion => "s8" }, }, } *** Version: s9 *** { global => { variables => { base => "s9/exe/group", dir => "root", exe => "exe_state", variant => 10, version => "s9", }, }, }
-- Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Conditional statements for template
by AnomalousMonk (Archbishop) on Mar 20, 2014 at 17:12 UTC | |
by kcott (Archbishop) on Mar 21, 2014 at 01:12 UTC | |
by AnomalousMonk (Archbishop) on Mar 21, 2014 at 02:09 UTC |