in reply to Info based on total changes

As posted, /me wants to know what is the Perl nexus? You seem to be saying you have a vi question since the perl script ( cfacr.pl ? )is done before you can work out the spacing: is that true, or would you like to post some code that shows why this is a SOPW question?

Update for clarity and order: Maybe you should re-write the "script" to count digits in your dollar amounts, if they're available to you in the form you show. </update>

OTOH, and w_a_a_ a _ y out in a WAG: have you considered such operators as reverse which might be useful to bring you to largest $number first, after which spacing and decimal alignment is, at least, possible.

Alternately, tell us where the "fac" values come from. Your sample data suggests they are nothing more or less than shortened forms of your $. That suggests, to /me, that you might count the digits before the decimal (or missing decimal) to determine you alignment needs. and if the fac values come from some representation of the $numbers, work the problem from the $numbers.

Or, perhaps working on clarity of exposition (and precision and completeness) might suggest other ways to do business.

Replies are listed 'Best First'.
Re^2: Info based on total changes
by pqocpiha (Initiate) on Jun 20, 2012 at 19:21 UTC
    the numbers in parenthesis are the midpoint (if 2 numbers are present in the string). The fac= is a duplicate of that midpoint. If there's only 1 number in the string, then that one number is used for both the number in parenthesis as well as the fac= number.
    while (<>) { chop; if ($_ =~/(.*)/) { $string = $1; $string =~ s/,000//g; $string =~ s/,//g; @numbers= $string =~ /(\d+)/g; $f= $numbers[0]; $s= $numbers[1]; $isf9 = substr($f,-3); if ($isf9 =~/999/) {$f=$f + 1;} $iss9 = substr($s,-3); if ($iss9 =~/999/) {$s=$s + 1;} $f =~ s/000//g; $s =~ s/000//g; #print join (" ",@numbers); if ($f>0 && $s>0){ $fac = (($s-$f)/2)+$f;} if ($f>0 && $s<1){ $fac = $f;} if ($fac>0) { $_ =~ s/^/($fac) /; $_ =~ s/$/;fac=$fac/; } } print "$_\n"; }
      1. I missed the significance of the $fac value. my bad!
      2. You told us you "start with" the $fac values. Now you show that's not the case. Your bad!
      3. Since you are calculating that, you have all the data points needed to solve your alignment problem.
      4. chop does NOT do what you appear to think it does. See the docs for chop and chomp, the latter of which more reliably removes a trailing newline (as opposed to discards the final entity on a line).
      5. The regex matches in your initial test, above, if ($_ =~/(.*)/) {...}? matches anything or nothing (ie, is useless or 'ALWAYS true-for-any-non-blank-line'): the dot means any character (alpha, digit, punct, or whitespace (except \n and the * quantifier means "none" or "any-quant-more-than-none" (see perlre).
      6. Var names such as $f, $s may be 'meaningful' to you, today... but they're apt to give grief, agitta and annoyance to some future you - or to the homicidal maniac who knows where you live and who may have to take over maintenance someday. Name vars with names or obvious and unambiguous abbreviations. They'll save you g,a and a.

      So, bottom line, I'm not giving you the code to solve your alignment problem; you'll learn more by solving that yourself, with the info you now have in hand, than by getting an algorithm spelled out or by copying code. But before you tackle that one, read the cited regex doc, and probably the tuts here. (Yes, they're directly relevant to one approach.)

        I'm very willing to read the tuts, but the link you provided matches nothing. Thanks just the same!