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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:31:00+00:00 2026-06-17T10:31:00+00:00

I’m writing in Perl to direct my report in table format but I’m having

  • 0

I’m writing in Perl to direct my report in table format but I’m having issue whenever the data filling is texted too long. Is there a way a write the code so that it can wrapped the lines to m ultiple. Here is my code and output. Thanks!

printf "\n%-${max1}s %-${max2}s %-15s\n", "====", "====", "=====" ;
printf "%-${max1}s %-${max2}s %-15s\n", "Code", "Item", "Group" ;
printf "%-${max1}s %-${max2}s %-15s\n", "====", "====", "=====" ;

foreach my $f (@{$rpt_ptr}) {
printf "%-${max1}s %-${max2}s %-15s\n", "$$f{code}", "$$f{item}", "$$f{group}", 
}

The output table will be extended to too long if I have the Item list which is too long, ie:-

====  =====                                                                                =====      

Code  Item                                                                                 Group

====  =====                                                                                =====

A1011 aaaaaa, bbbbb, ccccc, ddddd, eeeee, fffff, ggggg, hhhhh, iiiii, jjjjjj, kkkkk, llll    B
    B101  cccccc                                                                                 A

I’m aspected if I can comes out with a table such like:

====  =====                                                                                =====      
Code  Item                                                                                 Group
====  =====                                                                                =====
A1011 aaaaaa, bbbbb, ccccc, ddddd,                                                           B
      eeeee, fffff, ggggg, hhhhh,   
      iiiii, jjjjjj, kkkkk, llll
B101  cccccc                                                                                 A

How am I going to achieve that?

  • 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-17T10:31:01+00:00Added an answer on June 17, 2026 at 10:31 am

    Perl was originally written to format text files. It includes a rather interesting form generating facility, including the ability to wrap lines the way you’ve specified. I have not seen it used in a long, long while, but it’s still part of the language.

    It’s in the Perldoc under perlform.


    Example

    #! /usr/bin/env perl
    
    use strict;
    use warnings;
    use feature qw(say);
    
    my ($invoice, $description, $amount);
    while ( chomp ( my $line = <DATA> ) ) {
        ( $invoice, $description, $amount ) = split /:/ => $line;
        write;
    }
    
    format STDOUT_TOP =
    Invoice   Description       Amount
    =======   ===========       =======
    .
    format STDOUT = 
    @<<<<<<   ^<<<<<<<<<<<<<<   @###.##
    $invoice, $description,     $amount
              ^<<<<<<<<<<<<<<
              $description
              ^<<<<<<<<<<<<<<
              $description
              ^<<<<<<<<<<<<<<
              $description
              ^<<<<<<<<<<<<<<
              $description
    .
    __DATA__
    One:This line contans a lot of text that I have to process and I have no idea what it is:2.30
    Two:Here's another line that contains lots of data that won't fit on a single line:4.40
    Three:And one more line of extra long data that may or may not fit on a single line:5.10
    

    Output

    Invoice   Description       Amount
    =======   ===========       =======
    One       This line            2.30
              contans a lot
              of text that I
              have to process
              and I have no
    Two       Here's another       4.40
              line that
              contains lots
              of data that
              won't fit on a
    Three     And one more         5.10
              line of extra
              long data that
              may or may not
              fit on a single
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to construct a data frame in an Rcpp function, but when I
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am writing an app with both english and french support. The app requests
I'm having trouble keeping the paragraph square between the quote marks. In firefox the

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.