in reply to CGI Input with Escaped Characters

If it is a GET query, then the original data should be in $ENV{QUERY_STRING} iirc.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Replies are listed 'Best First'.
Re^2: CGI Input with Escaped Characters
by hoyt (Acolyte) on Apr 02, 2017 at 16:51 UTC
    That looks correct, and may work, but I try to keep the Perl code so that it'll work from command line too for troubleshooting. When I output the $ENV{} from command line, it doesn't show to that as an available key. Would that only work from a web posting action? Thanks!

      You can pass CGI parameters on the command, using data=foo api_key=1234. See the DEBUGGING section of CGI. But I doubt that CGI will shoehorn that back into %ENV.

      You could set the environment variable on the command line also

      $ env QUERY_STRING=data=foo&api_key=laurel%26hardy script.cgi

      or you could check inside your script if it is run from the commandline:

      if (-t STDIN) { # command line. for params, substitute special chars (e.g. & => %2 +6) # (there must be a module out there which does that for you) } else { # via webserver }
      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'