1

I want to run a script which uses JSON on my website. I've tested the following script in the cgi-bin folder with success:

#!/usr/local/bin/perl

print "Content-Type: text/html \n\n";
print "<h1 align=center>\n";
print "Welcome to my website\n";
print "</h1>\n";

But as soon as I include the JSON module, the website's CMS (OpenCart) reverts to a "Page cannot be found" error:

#!/usr/local/bin/perl

use JSON;

print "Content-Type: text/html \n\n";
print "<h1 align=center>\n";
print "Welcome to my website\n";
print "</h1>\n";

A rep from the website host confirmed JSON is installed on the (linux) server

Am I using the correct syntax to include JSON in my script?

DirkvdL
  • 21
  • 4
  • Can you find the CMS logs and see what the exact error from Perl was? That, or simply run your script on command line – DVK Jun 18 '13 at 19:27
  • Also, check if you have JSON or JSON::PP installed (the latter was in the core Perl since 5.14): `perl -MJSON -e ''` and `perl -MJSON::PP -e ''` – DVK Jun 18 '13 at 19:29
  • obligatory http://stackoverflow.com/questions/2165022/how-can-i-troubleshoot-my-perl-cgi-script – mob Jun 18 '13 at 20:00
  • @DVK Couldn't find any logs related to the Perl script in my cgi-bin folder, but thanks for your second comment, that helped me solve this. – DirkvdL Jun 19 '13 at 16:08
  • @mob I went through the valuable link, thanks, will be sure to pass it along – DirkvdL Jun 19 '13 at 16:09

1 Answers1

1

DVK commented:

Also, check if you have JSON or JSON::PP installed (the latter was in the core Perl since 5.14): perl -MJSON -e ''and perl -MJSON::PP -e ''

Thanks DVK, if I include use JSON::PP instead of use JSON, the script works.

I had to change some JSON-specific functions to JSON::PP functions (ie. change $json->objToJson to $json->encode) for it to work with JSON::PP.

This link also provided some help

Community
  • 1
  • 1
DirkvdL
  • 21
  • 4