in reply to hash problems

This code seems to do the trick....
$string =~ s/%([0-9][A-Z0-9])/$hash{$1}/ge;

I added the "e" option to the regular-expression replacement to have it execute the code... I also changed \1 to $1 and removed the single quotes.

Les Howard
www.lesandchris.com
Author of Net::Syslog and Number::Spell

Replies are listed 'Best First'.
RE: Re: hash problems
by mikfire (Deacon) on Apr 04, 2000 at 20:48 UTC
    For what little it is really worth, you do not need the e modifier on this version ( as opposed to chromatic's suggestion ).

    Both parts of the regex get double-quotish expansion, which will cause $hash{$1} to be expanded correctly.

    The original problem was using the \1 as the backreference. That has been depricated since at least perl 5.004 ( maybe earlier, I cannot remember precisely ).

    In fact, if you try to use the \1 on the command line and use perl -w, it will complain quite loudly. The moral here, of course, is make sure you use -w when developing code.

    You also used the single quotes ('') around the variable, which would have prevented the \1 from being expanded even if \1 wasn't deprecated. Remember, single quotes mean literally and double quotes will do... well, double-quotish expansion.

    Mik

RE: Re: hash problems
by zsh (Initiate) on Apr 04, 2000 at 19:09 UTC
    Thanks, this fixes it exactly.