in reply to Passing a regex from a CGI HTML form

OK, I changed tact and looked for a way to use $var's in the substition. I found a post on stackoverflow that works 'perfectly' for my precise requirements.

On the HTML form, have two 'input type="text"' boxes. One is for the text to find, the second is for the text to replace.

The perl code is as follows:

if ($request{'find'} && $request{'replace'}) { $find=$request{'find'}; $reptemp=$request{'replace'}; $replace='$reptemp'; $line =~ s/$find/$replace/ee; }

Bingo, all works great, and no "Danger, Will Robinson" type stuff :)

Nick

Replies are listed 'Best First'.
Re^2: Passing a regex from a CGI HTML form [SOLVED]
by Anonymous Monk on Sep 01, 2016 at 19:09 UTC

      Yes, but the code is simple. Secondly, all you need is a bit of 'magic' in the 'find' text box that the code looks for. If it exists then strip the 'magic' and proceed - if not, exit;

      Also, as I keep reiterating, this is a private page, on my own server, using my own code, with a hidden page that only I know ~ there really is no danger, Will Robinson'. I am not stupid.

      Nick

        Yes, but the code is simple. Secondly, all you need is a bit of 'magic' in the 'find' text box that the code looks for. If it exists then strip the 'magic' and proceed - if not, exit; Also, as I keep reiterating, this is a private page, on my own server, using my own code, with a hidden page that only I know ~ there really is no danger, Will Robinson'. I am not stupid.

        Its your choice if you want to use string eval, there is nothing to debate there, no need to justify your choice, you made the choice its yours

        but calling it "safe" or not-dangerous is dishonest stupid