in reply to Format string and regex question

Without the /g (global) modifier, the subsitution only fires once. Try
    $format_string =~ s/%(\w)/eval "$$1"/ge;

Replies are listed 'Best First'.
Re: Re: Format string and regex question
by repson (Chaplain) on Jan 01, 2001 at 16:04 UTC
    Just one slight problem...
    $$ is the current program pid, since $1 is not a scalar ref to dereference. It might be better to quote the first $ sign if this behaviour is not desireable (which would have been the cause for half of the original problem as well).

    $format_string =~ s/%(\w)/"\$$1"/eeg;

    And the second eval can be moved outside.