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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:17:46+00:00 2026-05-18T08:17:46+00:00

For simple output formatting I tend to use printf where I used write/format in

  • 0

For simple output formatting I tend to use printf where I used write/format in the days of Perl 4. However sometimes it seems the simplest solution for variable numbers of output lines per data record. For example

#!/usr/bin/perl
use strict;
use warnings;

my ($lorem, $aprille);

format =
@# ^<<<<<<<<<<<<<<<<<<<<<<<< | ^<<<<<<<<<<<<<<<<<<
$.,$aprille                  , $lorem
   ^<<<<<<<<<<<<<<<<<<<<<<<< | ^<<<<<<<<<<<<<<<<<< ~~
   $aprille                  , $lorem
                             |
.

while(<DATA>) {
  ($aprille, $lorem) = split(/\|/, $_, 2);
  write;
}

__DATA__
WHAN that Aprille with his shoures soote       |Lorem ipsum dolor sit amet,
The droghte of Marche hath perced to the roote,|consectetur adipisicing elit,
And bathed every veyne in swich licour,        |sed do eiusmod tempor
Of which vertu engendred is the flour;         |incididunt ut labore et dolore
Whan Zephirus eek with his swete breeth        |magna aliqua. Ut enim ad minim
Inspired hath in every holt and heeth          |veniam, quis nostrud
The tendre croppes, and the yonge sonne        |exercitation exercitation
Hath in the Ram his halfe cours y-ronne,       |ullamco laboris nisi ut ali-
And smale fowles maken melodye,                |quip ex ea commodo conse-
That slepen al the night with open ye,         |quat. Duis aute irure dolor
So priketh hem nature in hir corages:          |in reprehenderit in volup-
Than longen folk to goon on pilgrimages,       |tate velit esse cillium dol-
And palmers for to seken straunge strondes,    |ore eu fugiat nulla pariatur.
To ferne halwes, couthe in sondry londes;      |Lorem ipsum dolor sit amet,
And specially, from every shires ende          |consectetur adipisicing elit,
Of Engelond, to Caunterbury they wende,        |sed do eiusmod tempor
The holy blisful martir for to seke,           |incididunt ut labore et dolore
That hem hath holpen, whan that they were seke.|magna aliqua. Ut enim ad minim
And now for something completely different. Nice plumage.|Norwegian blue.

Produces

   1 WHAN that Aprille with    | Lorem ipsum dolor
     his shoures soote         | sit amet,
                               |
   2 The droghte of Marche     | consectetur
     hath perced to the roote, | adipisicing elit,
                               |
   3 And bathed every veyne in | sed do eiusmod
     swich licour,             | tempor
  ...
  19 And now for something     | Norwegian blue.
     completely different.     |
     Nice plumage.             |

Note that record 19 occupies three lines.

What is an equivalent concise perl5ish way to do the above without using write and format?

  • 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-18T08:17:47+00:00Added an answer on May 18, 2026 at 8:17 am

    The main problem with formats is the reliance on global variables. For other problems with formats, see pages 449 – 454 of Perl Best Practices.

    The modern solution would be Perl6::Form. This is a backport of what they are planning for Perl 6.

    What follows is a rough translation of your format code to Perl6::Form. I do not know Perl6::Form very well, so there may be ways to make it better or truer to your original example:

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    use Perl6::Form;
    
    while(<DATA>) {
        my ($aprille, $lorem) = split(/\|/, $_, 2);
        print form(
            "{>} {[[[[[[[[[[[[[[[[[[[[[[[[} | {[[[[[[[[[[[[[[[[[[}",
            $.,  $aprille,                  $lorem,
            "                               |                     ",
        );
    }
    
    __DATA__
    WHAN that Aprille with his shoures soote       |Lorem ipsum dolor sit amet,
    The droghte of Marche hath perced to the roote,|consectetur adipisicing elit,
    And bathed every veyne in swich licour,        |sed do eiusmod tempor
    Of which vertu engendred is the flour;         |incididunt ut labore et dolore
    Whan Zephirus eek with his swete breeth        |magna aliqua. Ut enim ad minim
    Inspired hath in every holt and heeth          |veniam, quis nostrud
    The tendre croppes, and the yonge sonne        |exercitation exercitation
    Hath in the Ram his halfe cours y-ronne,       |ullamco laboris nisi ut ali-
    And smale fowles maken melodye,                |quip ex ea commodo conse-
    That slepen al the night with open ye,         |quat. Duis aute irure dolor
    So priketh hem nature in hir corages:          |in reprehenderit in volup-
    Than longen folk to goon on pilgrimages,       |tate velit esse cillium dol-
    And palmers for to seken straunge strondes,    |ore eu fugiat nulla pariatur.
    To ferne halwes, couthe in sondry londes;      |Lorem ipsum dolor sit amet,
    And specially, from every shires ende          |consectetur adipisicing elit,
    Of Engelond, to Caunterbury they wende,        |sed do eiusmod tempor
    The holy blisful martir for to seke,           |incididunt ut labore et dolore
    That hem hath holpen, whan that they were seke.|magna aliqua. Ut enim ad minim
    And now for something completely different. Nice plumage.|Norwegian blue.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I frequently use HTML output in applications, up to now I've used some simple
Here is a simple program to output to a text file: #include <iostream> #include
I recently faced a problem of presenting the output of simple genetic algorithm that
Is there a simple way of redirecting serial port output to a file, that
I have a simple gateway listener which generates a log at the screen output
im using Views to output a block, containing latest post titles - simple and
I have written a very simple control. C# Visual Studio 2008. Its output should
I wrote the following Perl script (below) in order to create simple XML file.
I'm tinkering with writing a simple text-based role-playing game. I would like to use
What I'm trying to do is automatically change the output format of dates in

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.