Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Formatting Into Columns

by kevinw (Novice)
on Jul 23, 2002 at 20:56 UTC ( [id://184587]=perlquestion: print w/replies, xml ) Need Help??

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

Hi, I have the following code that prints out data
foreach $key (sort keys %hash) { print "$key\n$hash{$key}\n"; }
but the data for each $hash($key) is of different length....how would i format this to get the data to be in straight columns? from
type abcdef 12 11 19 obc 1 3 4
to
type abcdef 12 11 19 obc 1 3 4
thanks

Replies are listed 'Best First'.
Re: Formatting Into Columns
by PhiRatE (Monk) on Jul 23, 2002 at 22:10 UTC
    perldoc perlform

    # Define the format, left align first, right align remainder format Schema = @<<<<<<<< @>>>>> @>>>>> @>>>>> $key, $s[0], $s[1], $s[2] . $~ = "Schema"; # Set the format we're going to use for $key (sort keys %hash) { @s = split(' ',$hash{$key}); write; }

    Enjoy. (Consider in your next post specifying the exact format of $hash{$key}, in this case I've assumed it was a space-seperated string of numbers, but maybe it was an array-ref instead and you just didn't mention the join..)

Re: Formatting Into Columns
by emilford (Friar) on Jul 23, 2002 at 21:08 UTC
    Check out this node. It may help you along your way. You could probably also use printf and sprintf in this situation. HTH
Re: Formatting Into Columns
by ehdonhon (Curate) on Jul 23, 2002 at 21:08 UTC

Log In?
Username:
Password:

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

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

    No recent polls found