in reply to Re: Syntactical changes in Perl 5.8 from 5.6.1
in thread Syntactical changes in Perl 5.8 from 5.6.1

According to 'perldoc -f sprintf'(Perl 5.6.1) the "l" flag used between % and the conversion letter, interprets an integer as C type "long" or "unsigned long".
I must admit that I am a bit mathematically challenged so, I'm still foggy on the difference between a "floating point number(%f) and a long floating point number(%lf). Any further clarification or documentation would be greatly appriciated.

Also, I still don't see anything in the perldelta manpage that either deprecates the "%lf" or mentions that there has been a change in syntax.

Thanks for your assistance!

  • Comment on Re: Re: Syntactical changes in Perl 5.8 from 5.6.1

Replies are listed 'Best First'.
Re: Syntactical changes in Perl 5.8 from 5.6.1
by Abigail-II (Bishop) on Oct 10, 2003 at 17:16 UTC
    Indeed, it interprets an integer as C type "long" or "unsigned long". But %f is a conversion for floats, not integers.

    Also, I still don't see anything in the perldelta manpage that either deprecates the "%lf" or mentions that there has been a change in syntax.
    It actually might be this:
    o The Gconvert macro ($Config{d_Gconvert}) used by perl for stringifying floating-point numbers is now more picky about using sprintf %.*g rules for the conver- sion. Some platforms that used to use gcvt may now resort to the slower sprintf.

    But I'm not sure. And not everything is documented, the people working on Perl are only human!

    Abigail

      And not everything is documented, the people working on Perl are only human!

      I've met a couple of them, they are not what I would characterize as human, perhaps super-human.

      Maybe I should elaborate on these scripts. They were conversions from python, and only accept integers and only return integers. They all look similar except for the operator, and are as follows:

      if ($#ARGV != 1) { die "Usage: div numerator denominator\n" } foreach (@ARGV) { die "Integers only\n" if (/\D+/); } my $tot = sprintf "%lf\n", ($ARGV[0]/$ARGV[1]); $tot =~ s/(\d+)(\.\d+)/$1/; print $tot;

      Perhaps someone can suggest a better way. These were very quicky hammered together to fix a problem with some scripts that rely on them after an OS upgarde.
        The last three lines can be written as:
        print int ($ARGV [0] / $ARGV [1]);

        Abigail