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

  • Home
  • SEARCH
  • 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 203569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:23:25+00:00 2026-05-11T17:23:25+00:00

I have a test generator written in Perl. It generates tests that connect to

  • 0

I have a test generator written in Perl. It generates tests that connect to a simulator. These tests are themselves written in Perl and connect to the simulator via its API. I would like the generated code to be human-readable, which means I’d like it to be properly indented and formatted. Is there a good way to do it?

Details follow, or you can skip to the actual question below.

This is an example:


my $basic =  ABC
        TRIGGER        => DELAY(
            NUM            => 500,
            ),
        )
BASIC

my $additional =  STATE_IS(
        STATE          => DEF,
        INDEX          => 0,
        ),

ADDITIONAL

I’d like the command ABC to be executed with a delay of 500 (units aren’t relevant just now) after I call &event, and the state of index 0 is DEF. Sometimes I’ll also want to wait for indeces 1, 2, 3 etc…

For only one index I’d like to see this in my test:


    &event(
        CMD            => ABC
        TRIGGER        => DELAY(
            NUM            => 500,
            TRIGGER        => STATE_IS(
                STATE          => DEF,
                INDEX          => 0,
                ),
            ),
        )

For two indeces I’d like to see:


    &event(
        CMD            => ABC
        TRIGGER        => DELAY(
            NUM            => 500,
            TRIGGER        => STATE_IS(
                STATE          => DEF,
                INDEX          => 0,
                TRIGGER        => STATE_IS(
                    STATE          => DEF,
                    INDEX          => 1,
                    ),
                ),
            ),
        )

So basically I’m adding a block of:


            TRIGGER        => STATE_IS(
                STATE          => DEF,
                INDEX          => 0,
                ),

for each index, and the index number changes.

Here’s how I’m doing it:


for $i (0..$num_indeces) {
    # update the index number
    $additional =~ s/(INDEX\s*=>\s*)\d+,/$1 $i,/;

    $basic =~ s/(
                (\),\s*)  # capture sequences of ),
                +         # as many as possible 
                \)\s*     # end with ) without a , 
}               )/$additional $1/sx; # replace with the additional data

Here’s the actual question

The problem here is that the code comes out poorly indented. I’d like to run the resulting $basic through a prettifier like this:

&prettify($basic, "perl");

Which would format it nicely according to Perl’s best practices. Is there any good way to do this?

  • 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-11T17:23:25+00:00Added an answer on May 11, 2026 at 5:23 pm

    I have used this:

    use Perl::Tidy;
    sub Format {
        my $source = shift;
        my $result;
        Perl::Tidy::perltidy(
            source      => \$source,
            destination => \$result,
            argv        => [qw(-pbp -nst)]
        );
        return $result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a test file that contains tests taking quite a lot of time
I have a database process written in PL/SQL that i would like to test
I have written a JSON parser that takes any valid json string and generates
I have some specs, written in RSpec, that test various models. I use Factory
I have a test winforms app with ThreadExceptionHandler that displays a message box when
I have a test file that has many lines, each line looks something like:
I have a test file that contains 1,2,3 2,3,4 5,6,7 I want to insert
I have a data processing system that generates very large reports on the data
Studing STL I have written a a simple program to test functors and modifiers.
I have written a simple test application using asp.net mvc with C#. The application

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.