Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Conditional statements for template

by choroba (Cardinal)
on Mar 20, 2014 at 10:24 UTC ( [id://1079061]=note: print w/replies, xml ) Need Help??


in reply to Conditional statements for template

You are missing a dollar sign before the variable name.

You cannot use if in an expression, but you can use the Conditional Operator (aka the Ternary operator):

#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my $group = 'g'; my $exe = 'e'; for my $s_version (qw(s8 s9)) { my $template = { global => { variables => { version => "${s_version}", ($s_version eq "s8") ? (base => "\${version}/$group" +) : ( exe => "\${exe_state}", base => "\${s_version/${exe} +/$group" ), variant => "10", dir => "\${root}", }, }, }; print Dumper $template; }

Update: code formatting.

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1079061]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-26 02:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found