in reply to Auto-dailies

these lines:

if ($aolstats =~ /(\d+),(\d+)/) { $aolstats = $1 . $2; } if ($msnstats =~ /(\d+),(\d+)/) { $msnstats = $1 . $2; } if ($wwwstats =~ /(\d+),(\d+)/) { $wwwstats = $1 . $2; }

could be simplified as:

$aolstats =~ s/(\d+),(\d+)/$1$2/; $msnstats =~ s/(\d+),(\d+)/$1$2/; $wwwstats =~ s/(\d+),(\d+)/$1$2/;

or even:

s/(\d+),(\d+)/$1$2/ for ($aolstats,$msnstats,$wwwstats);

and of course, if you are dealing with numbers like 1,000,000, you'll want to add a 'g' flag to the substitution.

anders pearson

Replies are listed 'Best First'.
Re: Re: Auto-dailies
by blakem (Monsignor) on Aug 22, 2002 at 16:15 UTC
    if you are dealing with numbers like 1,000,000, you'll want to add a 'g' flag to the substitution.
    Something like:
    s/(\d+),(\d+)/$1$2/g for ($aolstats,$msnstats,$wwwstats);
    perhaps? Actually that wouldn't work because the two regexes overlap... You're trying to take '1,234,567' and squeeze the '234' grouping into $2 for the first match, and $1 for the next one.

    Since the comment in the original code reads: "Get rid of the comma in stats", I would write it like this:

    tr/,//d for $aolstats, $msnstats, $wwwstats;

    -Blake