James Parsons wrote:

> Ok here  go's ,  I'm just starting to Learn Perl  and it's a very slow
> process.
>
> 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..
>
> Thanks
> James Parsons.

Wow!  You are indeed new to Perl.  The dollar sign preceding total is not meant to 
represent the literal dollar sign.  It is one of the control characters which must be 
tacked on to any identifier, other than constants or function names, in Perl:

$ - scalar:  Basically any single value, including strings and references
@ - array:  A combination linked-list/array type container
% - hash:  A set of key-value pairs

To get a literal dollar sign in your print, you would probably want to escape a dollar 
sign, as:

printf ("\$%7.2f\n",$total);

Joseph


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

Reply via email to