in reply to Do regex using hash keys to wrapped template tokens

Ok, your regexes have some errors:
# use ${w}lc instead of $w\lc # because $w\lc is makes \l make "c" lowercase! $page_template =~ s/\Q$w$_$w/$input->param($_)/eg; $page_template =~ s/\Q${w}lc_\L$_\E$w/$input->param(lc)/eg; $page_template =~ s/\Q${w}uc_\U$_\E$w/$input->param(uc)/eg;
Those should work you.

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who could use a job
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re: Re: Do regex using hash keys to wrapped template tokens
by S_Shrum (Pilgrim) on Feb 15, 2002 at 05:08 UTC

    Hmmm...an odd thing is happening. Here is the code:

    if ( $input->param('debug') ) { print "<P>...replacing parameter token +s in final report"; } my $w = $input->param('wrapper'); for ( keys %input ) { if ( $input->param('debug') ) { print "<P>...replacing token: $_"; + } $page_template =~ s/\Q$w$_$w/$input->param($_)/eg; $page_template =~ s/\Q${w}lc_\L$_\E$w/$input->param(lc)/eg; $page_template =~ s/\Q${w}uc_\U$_\E$w/$input->param(uc)/eg; }

    I see the message on screen of "...replacing parameter tokens in final report" but I am not seeing any "...replacing token: __". Is the FOR loop set up correctly? At first I thought I was losing the contents of the hash but I know there are values in $input as the first 'debug' line is working.

    For that matter, I have tried everyones suggestions (thans to all for their time) with no luck meaning the tokens are not replaced in the final template. I'm stumped. I am doing replacements to record and table templates just fine. $page_template is the final to-be-displayed-to-the-user template.

    TIA.

    ======================
    Sean Shrum
    http://www.shrum.net

      Well, what is %input? Methinks you meant for (param) instead of for (keys %input)... sounds like someone's not using strict!

      _____________________________________________________
      Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a (from-home) job
      s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

        strict is in there (just commented out for right now ;-) I'm just taking care of the big bugs first...I can work on formalizing it later

        %input is a CGI created hash of a hash if I understand it correctly.

        Supplying just for (param) is not enough, right? I tried it with no success. How do I reference the param portion of %input for the FOR loop.

        TIA

        ======================
        Sean Shrum
        http://www.shrum.net

        Never mind....got it. A little trial and error produced: for ( $input->param() )

        From your code example, regular replaces are happening but lc_$_ and uc_$_ replaces are not transforming case; getting replaced with originally input case.

        ======================
        Sean Shrum
        http://www.shrum.net