James Parsons wrote: > Ok here go's , I'm just starting to Learn Perl and it's a very > slow process.
Super! Lots of help available here. Suggestion #1: Use a meaningful subject line; something like "Print floating dollar sign" would have been better than "Simple Perl Script" ("Perl Script" is redundant, and "Simple" doesn't tell us anything really). End of lecture :~) > > I have this script the calculates the sum a bunch of numbers and > prints the final number to file, but my problem is I would like the > number to have a floating $sign but I'm sure how do this > > Any help would be great > > > Script: > > #!/usr/bin/perl -w > > use strict; > > my $total = 0; > > open(FILE,"/usr/local/logs/pos/dollar_me") || die $!; > > $total += $_ while(<FILE>); > > close(FILE); > > printf ("%7.2f\n",$total); > > > The number comes out as 120.23 instead of $120.23.. You don't say if you want a fixed output width or not. If not, you can put the currency sign in the format string and leave off the width specifier: printf "\$.2f\n", $total; Note that I escaped the dollar sign so perl wouldn't think I was trying to interpolate a variable here. That will keep the dollar sign tight against the first digit. If you want that output to appear in a fixed field (say 10 columns), and yet still have the dollar sign float over against the first digit, it's more complicated. The easiest approach is probably: printf "%10s\n", sprintf('$%.2f', $total); n.b. when you come up against a problem like this, you should also peruse the FAQ's to see what they say (I didn't find anything specifically about this), and also check CPAN to see if there are any modules that do this kind of thing. A quick search of www.cpan.org for "Currency" turned up several modules that purport to deal with the problems of handling and displaying currency values. You might want to take a look at these. You can always peek at their source code to see how they are addressing the problem. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]