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


In reply to Re: Conditional statements for template by kcott
in thread Conditional statements for template by satya_rockstar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.