LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] sprintf formatting question

[ILUG] sprintf formatting question

Phil philb at vodafone.ie
Wed Aug 20 13:56:09 IST 2008


Hi,

I thought this one was obvious but seemingly not. I have a value, in 
excess of 2^32 that I want to print out using perl (ancient RedHat 8.0 
on 32 bit). The output should be padded to 10 characters.

First test works fine:
my $foo = 3188931580; # > 2147483648
print sprintf("%10u\n", $foo);

Second test, fails due to overflow
my $foo = 5188931580; # > 4294967295
print sprintf("%10u\n", $foo);

(actually prints out 4294967295)


My understanding was that a prefix of "L" or "ll" would indicate to 
sprintf that the value is a "long long" so that any of the following 
should work:

print sprintf("%10lld\n", $foo);	# Prints -1
print sprintf("%10llu\n", $foo);	# Print 4294967295
print sprintf("%10Ld\n", $foo);		# Prints -1
print sprintf("%10Lu\n", $foo);		# Prints 4294967295

Have I misunderstood the sprintf syntax or is this a limitation of perl 
on 32 bit?

Thanks,
  -Phil







More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell