Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'd like to print out my result like:
****** &&&&&&&&& ########################### ########################### ###########################
the third column maybe has more than one line(maybe two, three or four), how can I make it? Please help!! Thanks!!

2003-04-27 edit ybiC: retitle from "format"

Replies are listed 'Best First'.
Re: format
by The Mad Hatter (Priest) on Apr 27, 2003 at 20:49 UTC
    You could use Perl's internal format defintions. Here's an example that should work for you.
    #!/usr/bin/perl -w use strict; # Define various fields that we use in the format my $name = "TMH"; my $title = "PerlMonk"; my $story = 'The Mad Hatter (TMH) was a crazy monk. It was thought' . ' to be due to the mercury used to get rid of the dust ' . 'on hats...'; # This is the key part. A format is a series of fieldlines and # valuelines. Fieldlines define what the format looks like, valueline +s # specify what datagoes in the fields. Fields that start with @ are # fixed character widthfields. The < specifies that it is # left-justified. | (centered) and > (right-justified) are also # valid. The number of those specifiers is the width of the field. # The ^ is a filled field; it breaks text up (at word boundries) into # conveniently sized lines. The double tilde (~) at the beginning of # the third line specifies that the line should expand dynamically. # This allows the filled field to take up as many lines of that size a +s # it needs to. We use the format name STDOUT so that the format # affects that filehandle. format STDOUT = @<<<<<< @<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<< $name, $title, $story ~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<< $story . # Print doesn't work with formats, so write must be used. write # defaults to sending to STDOUT and looks for the format STDOUT. write;
    That prints
    TMH PerlMonk The Mad Hatter (TMH) was a crazy monk. It was thought to be due to the mercury used to get rid of the dust on hats...
    Added new code. Now with comments! ;-)
Re: format
by jmcnamara (Monsignor) on Apr 27, 2003 at 21:14 UTC

    Here is one way using Perl's format mechanism, see perlform:
    #!/usr/bin/perl -w use strict; my $str1 = "Knee"; my $str2 = 1; my $str3 = "Would it get some wind for the sailboat. " . "And it could get for it is. " . "It could get the railroad for these workers. " . "And it could be were it is."; format STDOUT = @<<<<< @<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<< $str1, $str2, $str3 ^<<<<<<<<<<<<<<<<<<<<<<<<<<~~ $str3 . write(); __END__ Prints: Knee 1 Would it get some wind for the sailboat. And it could get for it is. It could get the railroad for these workers. And it could be were it is.

    --
    John.

Re: format
by ctilmes (Vicar) on Apr 27, 2003 at 20:05 UTC