Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6813821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:36:53+00:00 2026-05-26T20:36:53+00:00

I have a script that writes an html page. Much of the content is

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:36:54+00:00Added an answer on May 26, 2026 at 8:36 pm

    One way to do it, poor-man’s templating in Perl strings:

    print qq!
    \$('td:nth-child(n)').show();
    \$('td:nth-child(@{[ $myVar + 2 ]}).removeClass('failCount');!
    

    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

    printf q!
    $('td:nth-child(n)').show();
    $('td:nth-child(%s).removeClass('failCount');!, $myVar + 2;
    

    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

    $template = q!
    $('td:nth-child(n)').show();
    $('td:nth-child([% myVar +2 %]).removeClass('failCount');!;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given that I have a JavaScript section in my HTML page like : <script
I have an upload script that write a index.html file, I modified it to
so i have ruby script that simply writes to a test.txt file with hello
I have a html page and inside of it there are 4 script tags
I have code below of an HTML page that includes a JS file. Function
i have an ajax for submit script on my html page, which loads a
I have a javascript routine that dynamically creates an HTML page, complete with it's
I want to write a script that changes page content but within a foreach
I have two links in the body of my html page that should make
I have a script called at the end of an html page like this.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.