I have a script that writes an html page.
Much of the content is fixed and so I use print qq! to output well formatted text in a single statement.
A few of the lines need a variable + 2 embedded in them, so I have ended up pre-calculating $myVarplus2, which is OK in this one case.
my $myVarPlus2 = $myVar + 2;
In TCL I could just use [expre $myVar + 2] within the statement. Is there a similar concept for Perl ?
This is the equivalent of what I would like to do
print qq!
$('td:nth-child(n)').show();!
$('td:nth-child([expr $myVar + 2])').removeClass('failCount');!
I would rather not break the statement up
print qq!
$('td:nth-child(n)').show();!
$('td:nth-child(" . $myVar + 2 . qq!').removeClass('failCount');!
but accept it may be the simplest approach.
One way to do it, poor-man’s templating in Perl strings:
It’s up to your own judgement whether you find that more readable than breaking the statement up, and at what point it becomes difficult to maintain.
Another way to do it would be printf
But perl golf aside, unless this is a simple throwaway project, in the long run I think you’d be best served by looking at Template Toolkit, then you can write your output like this