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

Hi Thanks for your reply.... The reason that I took that approach is that I have several scripts; the div one that you saw in the example but there is also a multiplication script. Since the result could not be expressed in scientific notation I chose to use "%lf" and the use regex to clean it up. This code was used to create the others by just changing the operators. Perhaps not the best method. The multiplication script follows:
#!/usr/bin/perl -w use strict; if ($#ARGV != 1) { die "Usage: mult integer integer\n" } foreach (@ARGV) { die "Integers only\n" if (/\D+/); } my $tot = sprintf "%lf\n", $ARGV[0] * $ARGV[1]; $tot =~ s/(\d+)(\.0+)/$1/; print $tot;

If you have any suggestions I'd love to hear them.

Thanks!

Replies are listed 'Best First'.
Re: Syntactical changes in Perl 5.8 from 5.6.1
by Abigail-II (Bishop) on Oct 14, 2003 at 19:11 UTC
    I've no idea what you are trying to do here. Since $ARGV [0] and $ARGV 1 are both integers, its product will be an integer too. Hence, their product will not have digits after the decimal point. Using sprintf and "%f" is a trick to avoid "scientific" output, when the result gets bigger than maxint, but you must realize the value will be inaccurate. However, there's no need for the substitution, the last three lines can be written as:
    printf "%.0f\n" => $ARGV [0] * $ARGV [1];

    Abigail