[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Bug in printf



There's a small bug in printf with strings and the # tag. The odd thing is
that the action changed from MacPerl 4 to MacPerl 5. A test program is:

$Str = 'excrutiating';
print "The original string is $Str\n";
@StrFmts = ('s', '4s', '.4s', '4.4s', '20.4s', '20.20s', '#20.20s');
foreach $Fmt (@StrFmts) {
    print "%$Fmt ==> |" . sprintf("%$Fmt", $Str) . "|\n";
}

Under MacPerl 4, the result is:
The original string is excrutiating
%s ==> |excrutiating|
%4s ==> |excrutiating|
%.4s ==> |excr|
%4.4s ==> |excr|
%20.4s ==> |                excr|
%20.20s ==> |        excrutiating|
%#20.20s ==> |        excrutiating|

Under MacPerl 5, the result is:
The original string is excrutiating
%s ==> |excrutiating|
%4s ==> |excrutiating|
%.4s ==> |excr|
%4.4s ==> |excr|
%20.4s ==> |                excr|
%20.20s ==> |        excrutiating|
%#20.20s ==> |xcrutiating|

Note the bad output on the last line.

Under Unix perl 4 and Unix perl 5.001m, the result is the same:
%s ==> |excrutiating|
%4s ==> |excrutiating|
%.4s ==> |excr|
%4.4s ==> |excr|
%20.4s ==> |                excr|
%20.20s ==> |        excrutiating|
%#20.20s ==> |        excrutiating|

--Paul Hoffman