Sara,
whenever you need to do any special formatting like this, especially
numbers,
use the "sprintf()" in  perlfunc - Perl builtin functions
for your case, try this:

print sprintf("%05.02f\n", 4.5 );
04.50

there are 2 other print formatters: report and "here documents".
I don't use the report method because I prefer the "here documents".
A "here document" is very nice, yet hardly documented within perl.
It involves just a TAG and a 2 special rules, here's and example:

print <<MY_TAG;
        I can put anything in here and it will be exactly that.
        I can put the variable "three=$three",
        I can put @vars in here.
             Everything expands.

        What's great is that there isn't all that "print ..." with
special characters!
        The above statement could require some escaping of the single
quote in print statements.

   Now, The 2 rules:
   #1 - the "<<" and the tag name "MY_TAG" must be together, ie, no
spacing.
   #2 - the end tag MUST be in column 1 and nothing else, ie, no end ";"
   so here's the end of this.
MY_TAG

You can store the "here doc" as a variable:
        my $message = <<MY_TAG;
stuf....
MY_TAG

cheers,
-stuart



-----Original Message-----
From: Sara [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, August 20, 2003 1:21 PM
To: beginperl
Subject: Formatting integer input


$one = 2.5;
$two = 2;
$three = $one + $two;

print "$three"; # prints     4.5

I want 4.5 in proper format as 04.05

Any ideas?

Thanks,
Sara.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to