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 8843453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:13:34+00:00 2026-06-14T11:13:34+00:00

I have a Perl code responsible for formatting output. Problem is I need to

  • 0

I have a Perl code responsible for formatting output. Problem is I need to calculate correct number of tabs to be put before one particular character in each string (let’s say it’s /). So instead of getting lines with different lengths I’d like to get fixed-length strings (but as short as possible, using the longest as max). How should I approach this?

Example of output (with format commented out, just raw array):

Long title with some looong words / short text
Another title / another short text

I need it like this:

title with some looong words / short text
Different title              / another short text

This was my first attempt, but it didn’t involve using tabs after one particular character.

my $text = Text::Format->new;

$text->rightAlign(1);
$text->columns(65);
$text->tabstop(4);

$values[$i] = $text->format(@values[$i]);
  • 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-06-14T11:13:35+00:00Added an answer on June 14, 2026 at 11:13 am

    There are two generally accepted ways to format text in Perl, so columns line up:

    • Use printf and sprintf. This is probably the most common way it’s done.
    • Use Perl Format capabilities. You define what you want a line to look like, then use write to print to that format.

    I haven’t seen people use Perl Format specifications stuff in years. It was a big feature back in Perl 3.x heydays because Perl was mainly used as a super-awk replacement language(Practical Extraction and Reporting Language). However, the mechanism is still there, and I’m sure it’ll be fun to learn.


    Now comes the second part of your query. You really don’t merely want the text to be formatted, you want it to be formatted with tabs.

    Fortunately, Perl has a built in module called Text::Tabs. It’s one of those modules that does one or two obscure tasks, but does them well.

    Actually, Text::Tabs doesn’t handle the two tasks it does well, but adequately.

    Produce your report using sprintf or the build in Perl formatting capabilities. Save your whole report in an array. It has to be an array because Text::Tabs doesn’t handle NLs. Then use the unexpand function to replace spaces in that array into another array with tabs.

    WORD ‘O WARNING: Text::Tabs does something very naughty: It imports the variable $tabstop into your program without asking your permission. If you use a variable called $tabstop, you’ll have to change it. You can set $tabstop to be the number of spaces a tab represents. It’s set to 8 as a default.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a perl code for processing file 'Output.txt' which has below Content.
I have a strange problem in matching a pattern. Consider the Perl code below
I have a Perl-Tk code and that code createas a GUI with 5 Tabs
I have some Perl code that I need to transpose in Java. In this
I have Perl code that uses the system() function to call robocopy.exe, but it
I have some Perl code that executes a shell script for multiple parameters, to
I have a Perl code that use threads and HTTP::Async with multiple outbound IP
I have run this Perl code: #!/usr/bin/perl print content-type: text/html \n\n; print Hello World.\n;
Let us say if I have a Perl module Resounces.pm with this code snippet
I have written the following code in Perl. I want to iterate through a

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.