This little Perl-function formats some strings to the same length.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#!/usr/bin/perl use strict; #example data my @arr = ("monday","tuesday","wednesday","thursday","friday","saturday","sunday"); #default for(@arr){ print $_.$/; } #formated to same size for(@arr){ print len_format($_,10).$/; } #format sub sub len_format{ my $str = shift; my $len = shift; return((" "x($len-length($str))).$str); } |
We could see the normal output then the formatted strings:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
monday tuesday wednesday thursday friday saturday sunday monday tuesday wednesday thursday friday saturday sunday |
I was recommended this blog by my cousin. I’m not sure whether this post
is written by him as no one else know such detailed about my problem.
You are amazing! Thanks!
Thanks for sharing your info. I truly appreciate your efforts and
I will be waiting for your further write ups thanks once again.
Wow, awesome blog layout! How long have you been blogging for?
you make blogging look easy. The overall look of your website is wonderful, as well
as the content!
It’s difficult to get educated people with this
topic, however you could be seen as you know what you’re talking about!
Thanks