I want to output strings into eight columns, but I want to keep the spacing the same. I don't want to do it in HTML, but I am not sure how to do it normally. Example:
Something Something Something Something Something
Else Else Else Else Else
Another Another Another Another Another
The amount of rows will change daily, but the column number will always stay the same. What is the best way to do this?
String provides format() method can be used to print formatted output in java.
Formats are the writing templates used in Perl to output the reports. Perl has a mechanism which helps in generating simple reports and charts. Instead of executing, Formats are declared, so they may occur at any point in the program.
print just outputs. printf takes a formatting string like "%3f" and uses it to format the output. sprintf is the same as printf except it doesn't actually output anything. It returns a formatted string.
printf
printf "%-11s %-11s %-11s %-11s %-11s %-11s %-11s %-11s\n",
$column1, $column2, ..., $column8;
Change "11" in the template to whatever value you need.
You could use Perl's format
.
This is probably the "complicated" method that you don't understand, most likely because it gives you many options (left|center|right justification/padding, leading 0's, etc).
Perldoc Example:
Example:
format STDOUT =
@<<<<<< @|||||| @>>>>>>
"left", "middle", "right"
.
Output:
left middle right
Here's another tutorial.
#!/usr/bin/perl -w
use strict;
sub main{
my @arr = (['something1','something2','something3','something4','something5','something6','something7','something8']
,['else1' ,'else2' ,'else3' ,'else4' ,'else5' ,'else6' ,'else7' ,'else8' ]
,['another1' ,'another2' ,'another3' ,'another4' ,'another5' ,'another6' ,'another7' ,'another8' ]
);
for my $row (@arr) {
format STDOUT =
@<<<<<<<<<<<< @<<<<<<<<<<<< @<<<<<<<<<<<< @<<<<<<<<<<<< @<<<<<<<<<<<< @<<<<<<<<<<<< @<<<<<<<<<<<< @<<<<<<<<<<<<
@$row
.
write;
}
}
main();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With