Perl Help For Newbie

Aaron Peterson aaron at alpete.com
Mon Apr 26 13:49:17 PDT 2004


for your regex, you might try something like:

foreach $line (@input_file)
{
    if ( ($val1,$val2,$val3) = $line =~
        /\$(\d\.\d\d)\s+\$(\d\.\d\d)\s+\$(\d\.\d\d)/ )
    {
        $changed = sprintf "%.2f",$val1 * 1.5;
        s/\$\d\.\d\d\s+\$\d\.\d\d\s+\$\d\.\d\d/\$$changed \$$val3/;
    }
}

perhaps the calculation and substitution could all be done in one line,
but it makes my head hurt to think about it.

Aaron


More information about the freebsd-questions mailing list