Skip Menu |

This queue is for tickets about the Getopt-Simple CPAN distribution.

Report information
The Basics
Id: 8260
Status: resolved
Worked: 20 min
Priority: 0/
Queue: Getopt-Simple

People
Owner: RSAVAGE [...] cpan.org
Requestors: rjbs [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Unimportant
Broken in: 1.47
Fixed in: (no value)



Subject: repeated formatting code
A number of times, code occurs that follows $string with (' ' x $length - length($string) This sort of thing is one of the most basic reasons for printf and sprintf. I have attached a patch which abstracts that padding into a subroutine.
diff -u -r Getopt-Simple-old/lib/Getopt/Simple.pm Getopt-Simple-new/lib/Getopt/Simple.pm --- Getopt-Simple-old/lib/Getopt/Simple.pm 2004-07-21 14:30:22.000000000 -0400 +++ Getopt-Simple-new/lib/Getopt/Simple.pm 2004-11-05 15:50:33.000000000 -0500 @@ -54,22 +54,23 @@ # -------------------------------------------------------------------------- +sub pad { sprintf "%-${fieldWidth}s", @_; } + sub dumpOptions { my($self) = @_; - print 'Option', ' ' x ($fieldWidth - length('Option') ), "Value\n"; + print pad('Option'), 'Value'; for (sort byOrder keys(%{$$self{'switch'} }) ) { if (ref($$self{'switch'}{$_}) eq 'ARRAY') { - print "-$_", ' ' x ($fieldWidth - (1 + length) ); - print '(', join(', ', @{$$self{'switch'}{$_} }), ")\n"; + print pad("-$_"), '(' . join(', ', @{$$self{'switch'}{$_} }) . ")\n"; } else { - print "-$_", ' ' x ($fieldWidth - (1 + length) ), "$$self{'switch'}{$_}\n"; + print pad("-$_"), "$$self{'switch'}{$_}\n"; } } @@ -131,15 +132,11 @@ print "$$self{'helpText'}\n" if ($$self{'helpText'}); - print 'Option', ' ' x ($fieldWidth - length('Option') ), - 'Environment var', ' ' x ($fieldWidth - length('Environment var') ), - "Default\n"; + print pad('Option'), pad('Environment var'), "Default\n"; for (sort byOrder keys(%{$$self{'default'} }) ) { - print "-$_", ' ' x ($fieldWidth - (1 + length) ), - "$$self{'default'}{$_}{'env'}", - ' ' x ($fieldWidth - length($$self{'default'}{$_}{'env'}) ); + print pad("-$_"), pad("$$self{'default'}{$_}{'env'}"); if (ref($$self{'default'}{$_}{'default'}) eq 'ARRAY') {
From: Ron Savage <ron [...] savage.net.au>
To: "rjbs [...] cpan.org via RT" <bug-Getopt-Simple [...] rt.cpan.org>
Date: Sat, 6 Nov 2004 10:42:10 +1100
Subject: Re: [cpan #8260] repeated formatting code
RT-Send-Cc:
On Fri,  5 Nov 2004 15:54:07 -0500 (EST), rjbs@cpan.org via RT wrote: Hi Show quoted text
> sprintf.  I have attached a patch which abstracts that padding into > a subroutine.
Thanx, but your msg arrived without an attachment :-(. -- Cheers Ron Savage, ron@savage.net.au on 6/11/2004 http://savage.net.au/index.html
From: Ron Savage <ron [...] savage.net.au>
To: "rjbs [...] cpan.org via RT" <bug-Getopt-Simple [...] rt.cpan.org>
Date: Sun, 2 Jan 2005 10:34:31 +1100
Subject: Re: [cpan #8260] repeated formatting code
RT-Send-Cc:
On Fri,  5 Nov 2004 15:54:07 -0500 (EST), rjbs@cpan.org via RT wrote: Hi Ricardo Just following up old emails... Show quoted text
> A number of times, code occurs that follows $string with (' ' x > $length - length($string) > > This sort of thing is one of the most basic reasons for printf and > sprintf.  I have attached a patch which abstracts that padding into > a subroutine.
V 1.48 incorporates your suggestion. -- Cheers Ron Savage, ron@savage.net.au on 2/01/2005 http://savage.net.au/index.html