in reply to sprintf zero-fill issue

You've hit an overflow. 2150004800 is bigger than 2^32/2. Due to the way computers handle positive/negative numbers, you end up with a negative number.

Try this and you should get a positive result:

my $var1alt = sprintf("%014d", $var1);
my $var2alt = sprintf("%014u", $var2);

The 'u' tells Perl to treat the variable as an unsigned integer.

See http://en.wikipedia.org/wiki/Printf for a detailed description

Replies are listed 'Best First'.
Re^2: sprintf zero-fill issue
by mlong (Sexton) on Jun 27, 2007 at 17:02 UTC
    Yep. That was it. I'm not sure how I missed that one.

    Thanks.

    -Matt
      Thanks to you both, this inadvertently helped correct an issue that I've had myself and had forgotten about until I saw this.