Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: aligning text

by Anonymous Monk
on Feb 02, 2018 at 15:28 UTC ( [id://1208330]=note: print w/replies, xml ) Need Help??


in reply to Re: aligning text
in thread aligning text

This is the output:

Belgian Waffles 5.95 Berry-Berry Belgian Waffles 8.95 French Toast 4.50 Homestyle Breakfast 6.95 Strawberry Belgian Waffles 7.95

And this is the desired output:

Belgian Waffles 5.95 Berry-Berry Belgian Waffles 8.95 French Toast 4.50 Homestyle Breakfast 6.95 Strawberry Belgian Waffles 7.95

Replies are listed 'Best First'.
Re^3: aligning text
by hippo (Bishop) on Feb 02, 2018 at 15:43 UTC

    Since I doubt anyone else will suggest it, here's a perlform-based solution:

    #!/usr/bin/env perl use strict; use warnings; my @har = ( 'Belgian Waffles', 'Berry-Berry Belgian Waffles', 'French Toast', 'Homestyle Breakfast', 'Strawberry Belgian Waffles', ); my @prices = qw/ 5.95 8.95 4.50 6.95 7.95 /; my ($name, $price); format STDOUT = @<<<<<<<<<<<<<<<<<<<<<<<<< @#.## $name, $price . for my $i (0 ..$#har) { $name = $har[$i]; $price = $prices[$i]; write; }
Re^3: aligning text
by dasgar (Priest) on Feb 02, 2018 at 15:57 UTC

    For that kind of formatting, I've used Text::Table as suggested by hippo. I'm not going to claim that this is the "best" way of doing, but I'd probably resort to using Text::Table if needed to format data into columns.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1208330]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-25 20:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found