Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: aligning text

by hippo (Bishop)
on Feb 02, 2018 at 15:16 UTC ( [id://1208328]=note: print w/replies, xml ) Need Help??


in reply to aligning text

but i'm not succeeding

Since you have not said (or shown) in what way you are not succeeding, we can only point you towards generic solutions such as perlform, printf, Text::Table, Template, etc. Hopefully one or other of those will give you the output you need.

While you're at it, you might want to consider one of the many XML modules (but not XML::Simple) for parsing the input.

Replies are listed 'Best First'.
Re^2: aligning text
by Anonymous Monk on Feb 02, 2018 at 15:28 UTC

    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

      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; }

      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://1208328]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-19 21:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found