in reply to Re: Evaluating a regex replacement value
in thread Evaluating a regex replacement value

You can rewrite
my $dum=$1; my $val; if ($dum) { $val = $value * $dum }else{ $val=$val +ue} $val
To be ($1 != 0)? ($value * $1) : $value like prasadbabu had it, or really it can just be boiled down to:
$value * ($1 || 1)
(Assuming that $value is alway numeric) No need for a temp variable or the explicit if/else.

also, since you're not chomp'ing $line, that "\n" in your print line is going to going to double-space the output...

Replies are listed 'Best First'.
Re^3: Evaluating a regex replacement value
by McDarren (Abbot) on Oct 05, 2005 at 14:09 UTC
    Thanks :)

    This is a nice, clean option and is what I've settled on.
    $line =~ s/<:KEYWORD:([^:>]*):?>/int($value * ($1 || 1))/e;
    The not chomp'ing was never an issue, as I wasn't explicity adding newlines to the output.

    heh... I've just been browsing through my copy of Perl Best Practices, and realised that I should abstract my KEYWORD<=>$values pairs into a lookup hash.... so I'm off to do that now :)

    Thanks again,
    --Darren