From dk-thamesvalley-pm at bdksol.co.uk Tue Jan 6 05:15:16 2009 From: dk-thamesvalley-pm at bdksol.co.uk (Duncan Kendall) Date: Tue, 6 Jan 2009 13:15:16 -0000 (UTC) Subject: [Thamesvalley-pm] Leading 0s problem with large integers In-Reply-To: References: Message-ID: <23276.212.36.40.194.1231247716.squirrel@mail.yeswhere.co.uk> Hello, I have a bit of code that is trying to format a number as a 10 digit string with leading 0s inserted as necessary. The code is: $number; $string = sprintf("%0*d", 10, $number); And this works just fine for values of $number up to 2147483647 ((2^31)-1). Changing it to: $string = sprintf("%0*u", 10, $number); improves things and works fine for anything up to ((2^32)-1). The system does not have 64 bit support, and so trying to persuade Perl that $number is a long long doesn't help. I can get around this wit a bit of string manipulation, calculating the number of digits and then manually inserting 0s at the start, but that isn't very elegant. Can anyone offer up a neat and simple solution? Thanks, Duncan From charlie at newint.org Tue Jan 6 05:23:39 2009 From: charlie at newint.org (Charlie Harvey) Date: Tue, 06 Jan 2009 13:23:39 +0000 Subject: [Thamesvalley-pm] Leading 0s problem with large integers In-Reply-To: <23276.212.36.40.194.1231247716.squirrel@mail.yeswhere.co.uk> References: <23276.212.36.40.194.1231247716.squirrel@mail.yeswhere.co.uk> Message-ID: <49635B5B.5060406@newint.org> Duncan Kendall wrote: > Hello, > > I have a bit of code that is trying to format a number as a 10 digit > string with leading 0s inserted as necessary. ---------8<------------- > Can anyone offer up a neat and simple solution? Its not especially elegant, but: $len = 10; $string = '0' x ($len - length $num) . $num; -- Charlie Harvey IT Manager New Internationalist t: +44 (0)1865 811402 f: +44 (0)1865 793152 w: http://www.newint.org/ New Internationalist is an independent not-for-profit communications cooperative. Our multi-award winning magazine, New Internationalist, brings to life the people, the ideas and the action in the fight for global justice. New Internationalist Publications Ltd. is incorporated in England under no.1005239. Registered Office: New Internationalist, 55 Rectory Road, Oxford, OX4 1BW, UK From Smylers at stripey.com Tue Jan 6 05:38:59 2009 From: Smylers at stripey.com (Smylers) Date: Tue, 6 Jan 2009 13:38:59 +0000 Subject: [Thamesvalley-pm] Leading 0s problem with large integers In-Reply-To: <23276.212.36.40.194.1231247716.squirrel@mail.yeswhere.co.uk> References: <23276.212.36.40.194.1231247716.squirrel@mail.yeswhere.co.uk> Message-ID: <20090106133859.GB4070@stripey.com> Duncan Kendall writes: > $string = sprintf("%0*d", 10, $number); > > And this works just fine for values of $number up to 2147483647 > ((2^31)-1). Changing it to: > > $string = sprintf("%0*u", 10, $number); > > improves things and works fine for anything up to ((2^32)-1). > > I can get around this wit a bit of string manipulation, calculating > the number of digits and then manually inserting 0s at the start, but > that isn't very elegant. Can anyone offer up a neat and simple > solution? Why does sprintf need to know that it's an integer? Using %0*s appears to do what you want. Smylers From dk-thamesvalley-pm at bdksol.co.uk Wed Jan 7 00:21:38 2009 From: dk-thamesvalley-pm at bdksol.co.uk (Duncan Kendall) Date: Wed, 7 Jan 2009 08:21:38 -0000 (UTC) Subject: [Thamesvalley-pm] Thamesvalley-pm Digest, Vol 19, Issue 1 In-Reply-To: References: Message-ID: <49896.80.177.204.35.1231316498.squirrel@mail.yeswhere.co.uk> > Date: Tue, 06 Jan 2009 13:23:39 +0000 > From: Charlie Harvey > > Its not especially elegant, but: > > $len = 10; > $string = '0' x ($len - length $num) . $num; Yes. That's pretty much what I came up with. Thanks. > Date: Tue, 6 Jan 2009 13:38:59 +0000 > From: Smylers > > Why does sprintf need to know that it's an integer? Using %0*s appears > to do what you want. Doh! That is much better - and far too obvious for me to see. Thanks. From adam.trickett at iredale.net Tue Jan 27 10:36:08 2009 From: adam.trickett at iredale.net (Dr A. J. Trickett) Date: Tue, 27 Jan 2009 18:36:08 +0000 Subject: [Thamesvalley-pm] [ANNOUNCE] London.pm technical meeting about "What is Moose and why is it the future?" on 19th Feb 2009 Message-ID: <200901271836.16188.adam.trickett@iredale.net> From the London.pm: > London Perl Mongers organises technical meetings every two months. The > technical meetings are a chance to find out what has been going on in > the Perl community, what techniques people are using and how Perl > integrates with other software. > > The next technical meeting will be on the 19th February 2009 from 7pm > to 9pm (you may arrive from 6.30pm, sign in at the reception) and the > theme is "What is Moose and why is it the future?". You have to sign > up to attend, see the website. > > It will be held at BBC's offices near White City. Many thanks to Peter > Edwards, the BBC and everyone involved for allowing us to use this > wonderful venue. > > To sign up and see more information, please visit: > > ? http://londonpmtech.appspot.com/ > > Regards, L?on -- Adam Trickett Overton, HANTS, UK Glory is fleeting, but obscurity is forever. -- Napoleon Bonaparte -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part. URL: