January 2019 Archives

What's going on here?

What do you think the following lines print?

use feature 'say';
sub fmt { sprintf( @_[0, 1] ) }
my $num = 1_234_567_890.12_345_678_9;
say sprintf( '%.6f', $num );
say fmt( '%.6f', $num );

I think the two say lines should both print out the same value, 1234567890.123457. The first line behaves as expected, but the second does not. Does anybody have any idea on why?

Playing around with the code, I’ve figured out how to fix the issue, but I’m curious as to thoughts and explanations from the community.

About $Bob

user-pic I blog about Perl.