Installing JSON.pm on a web host without shell access - json

My host (iPage) does not have JSON.pm installed. I don't want to use the modules they have installed (XML) in order to transfer data from a CGI script back to a web page. Is there anyway that I can use JSON without them installing it on Perl?
The reason I ask is because I noticed when I downloaded the JSON zip that I had to run a makefile json.pm command but I don't have access to a Unix shell or a SSH terminal.

If your Perl is new enough, 5.14 and up, it will come with JSON::PP, a pure Perl implementation of the JSON parser. Confusingly it does not come with JSON.pm. So try use JSON::PP and see if it works.
Otherwise, follow Ilmari's instructions. If you switch to a host with shell access, you can use local::lib to manage CPAN modules.

You should be able to install a local copy of the pure Perl version of the JSON module without shell access. Just download the .tar.gz archive to your own computer, unpack it and copy everything under the lib subdirectory to a suitable location on your webhost.
You'll also need to tell Perl where to find the module, for which you need to know the filesystem path to which you copied the module. For example, if you copied the contents of the lib directory to /home/username/perl-lib on your webhost, then you would include in your code the lines:
use lib '/home/username/perl-lib';
use JSON;
Depending on how your webhost is configured, you might also be able to use $ENV{HOME} to obtain the path to your home directory, so that you can write:
use lib "$ENV{HOME}/perl-lib";
use JSON;
or you could try using the FindBin module to find the path to the directory containing your script, and locate the lib directory from there (see the example in the FindBin documentation).

Related

How do I install a driver in Erlang? (Specifically MySQL-otp driver)

From the documentation this driver looks great. I don't know how to install it so that I can use it though. I read somewhere that I should maybe use rebar? I looked at that documentation though and it appears to have the opposite problem. It says how to install it, but not how to use it.
Update
So it looks like after installing rebar, I can add the lines
{deps, [
{mysql, ".*", {git, "https://github.com/mysql-otp/mysql-otp",
{tag, "1.3.3"}}}
]}.
to my file rebar.config. I don't know what this does though. Do I have to compile or make this file now? Does rebar.config have to be in the same directory as my project? Right not the path to rebar.config is ~/rebar/rebar.config
Is it all correct to place my project so that it is a sibling to rebar in the file hierarchy?
Update
I ran ./rebar get-deps with the rebar folder and got
Pulling mysql from {git,"https://github.com/mysql-otp/mysql-otp",
{tag,"1.3.3"}}
Cloning into 'mysql'...
==> mysql (get-deps)
I still don't really know what this means though, and when I try compiling my erlang file I receive the result.
c(erlangFile.erl).
{error,non_existing}
rebar is a build tool for erlang.Please go through https://github.com/rebar/rebar/wiki/Rebar-commands for the commands.
After getting dependency, "rebar compile" is required to compile it.
For using the beam files, you have to give output beam path using Add Path to Erlang Search Path?
these methods.
Then you will be able to use it in your code.
Download your package, in this case
git clone https://github.com/mysql-otp/mysql-otp.git
Download a tool called rebar
git clone git://github.com/rebar/rebar.git
cd rebar
./bootstrap
Add the following to rebar/rebar.config
{deps, [
{mysql, ".*", {git, "https://github.com/mysql-otp/mysql-otp",
{tag, "1.3.3"}}}
]}.
Within the rebar/mysql-otp directory run
./rebar get-deps
Then within the same directory, run
./rebar compile
This will put a bunch of .beam files and .app file into the ebin/ directory
Next add the ebin/ directory to your path. You can update your $ERL_LIBS environment variable, run an include command within the erlang console like
1> code:add_pathz("~/rebar/mysql-otp/ebin").
or
1> code:add_pathz("rebar/mysql-otp/ebin")
And theres a few other ways to add it to your Erlang path.
Also, make sure mysql is also installed
Heres a few links with mysql installation instructions that worked for me
https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-centos-7
No package msyql-server available

How to parse HTML into .txt format using C

I need to parse HTML into .txt format using C.
An example - it has to detect each
1. <p>
2. <tr>
3. <ul> etc...
and convert them into text (in a document)
Can somebody help please?
I think, the easiest way to download a html webpage in c is to use libcurl. Assuming you have already set up your development environment, follow these steps:
Visit the download page of libcurl and download its latest version.
take a look at the install page and learn how to install the library. For Linux, the installation is pretty straight forward, just type ./configure && make && make install in the terminal.
Download the url2file.c example of libcurl. The <curl/curl.h> header file which is exposed in this file essentially provides necessary functions to let you communicate with the web server.
Next, compile the url2file.c using gcc -o url2file url2file.c -lcurl.
Finally, test url2file using ./url2file http://example.com. The results will be stored in page.out file which is in plaintext.
NOTES:
You need to install the libcurl in order to be able to compile the url2file.c file, unless it will throw a fatal error.
If you have already installed the curl program on your machine, you can download webpages using curl http://example.com > page.out command in the terminal.
Also, wget lets you to download and store webpages: wget http://example.com.
This answer stores a webpage as a pliantext. It doesn't perform any specific html tag processing.

Using mysql from Perl in an Azure web app

I am using Azure to host a site which uses Perl and MySql. I have placed all my Strawberry perl files in the bin folder. I connect to Perl by adding a handler to the Perl executable which is located on my web app in d:\home\site\wwwroot\bin\perl\bin\perl.exe.
I can run simple Perl programs ok. However when I try to run a Perl script which connects to a MySql database I get the following error:
install_driver(mysql) failed: Can't load 'D:/home/site/wwwroot/bin/perl/vendor/lib/auto/DBD/mysql/mysql.xs.dll' for module DBD::mysql: load_file:The specified module could not be found at D:/home/site/wwwroot/bin/perl/lib/DynaLoader.pm line 193.
However mysql.xs.dll exists in that location. I have also copied into the same folder as mysql.xs.dll the file libmysql_.dll which I read somewhere was a dependency of mysql.xs.dll.
The datasource I am trying to get to looks like this:
my $data_source = "DBI:mysql:$database:$hostname";
I am using the same code and binary files as handlers for Perl in my local IIS so I think all the files needed are there in my bin folder.
What else can I try?

Trying to get RmySQL to work but not understanding bash's export or filesystem conventions

I am trying to install RMySQL on my mac (mavericks) and it errors out when I try to build it from source, saying:
Configuration error: could not find the MySQL installation include
and/or library directories. Manually specify the location of the
MySQL libraries and the header files and re-run R CMD INSTALL.
INSTRUCTIONS:
Define and export the 2 shell variables PKG_CPPFLAGS and PKG_LIBS to include the directory for header files (*.h) and
libraries, for example (using Bourne shell syntax):
export PKG_CPPFLAGS="-I"
export PKG_LIBS="-L -lmysqlclient"
Re-run the R INSTALL command:
R CMD INSTALL RMySQL_.tar.gz
I tried to follow the instructions by entering:
export PKG_CPPFLAGS="-I/usr/local/mysql/include" export
PKG_LIBS="-L/usr/local/mysql/lib -lmysqlclient"
but when I re-run RMySQL it still doesn't work. Moreover, if I type
$PKG_LIBS
to see what that variable holds, I get
-bash: -L/usr/local/mysql/lib: No such file or directory'
I know that /usr/local/mysql/lib exists and it does contain a mySQL header. Am I misunderstanding the instructions?
I'm asking here only after a lot of effort to find solutions and/or work arounds. Sucks being a noob sometimes.
I am going to assume you're trying to get RmySQL to run on R 3.1.0 on Mavericks? Rather than worry about exporting variables etc, here is a simple clean solution for you that should avoid the headaches.
The RMySQL install link Pascal provided above really is your solution. You're probably just stumbling on syntax, or getting things to work from the terminal.
Even if you're a "noob", you should be able to get this working. I'll try to offer a "dummy's guide" walk through here, as I bet there are many others who have this problem too, even after trying to read the RMySQL installation readme.
I would bet with very high confidence the problem is just that you aren't specifying correctly the locations of the library and header folders for compiling. Read the errors carefully when you try to compile... the errors will probably tell you a file/header is missing, or some .so file (shared object) is missing.
One simple way compile RMySQL from source on R 3.1.0, mavericks is as follows (this does not require you to set any environmental variables, no editing of the Renviron file, etc):
Does MySQL work by itself? i.e. Can you open/run it no problems? If not, fix that first.
Find the precise location of your mysql installation. For me, on Mavericks, I see mysql installed at /usr/local/mysql-5.6.17-osx10.7-x86_64 (your version number may be different). There is also another folder /usr/local/mysql which is an alias to /usr/local/mysql-5.6.17-osx10.7-x86_64 (/usr/local/mysql finds the current version of mysql you are using, if multiple mysql file folders exist, I think). In this directory, I see two sub directories (among many) called "include" and "lib". Take a look; "include" will contain header files (include as in #include , etc, in simple C++ programs). The "lib" folder contains compiled source code of the mysql library.
An easy way to compile and install RMySQL which doesn't exactly follow the suggested way to do it in the installation guide is this. Note that this is doing the same thing as in the installation guide, just a little easier as it's one command line from the terminal, once you know where your mysql install folder is. Go to the terminal, and type the following exactly, with one space between each chunk (with your mysql folder name adjusted appropriately for the version number):
PKG_CPPFLAGS="-I/usr/local/mysql/include/" PKG_LIBS="-L/usr/local/mysql/lib/ -lmysqlclient" R CMD INSTALL RMySQL_0.9-3.tar.gz
OR (the same thing, just more typing)
PKG_CPPFLAGS="-I/usr/local/mysql-5.6.17-osx10.7-x86_64/include/" PKG_LIBS="-L/usr/local/mysql-5.6.17-osx10.7-x86_64/lib/ -lmysqlclient" R CMD INSTALL RMySQL_0.9-3.tar.gz
Note for dummies: Make sure when you run this command, that you are doing it from the terminal in the directory that contains the RMySQL_0.9-3.tar.gz file (or whatever the name of your folder is that contains the RMySQL source code)
and RMySQL compiles!
Don't be afraid about trying to compile source code -- it's not just for 'compiled language programmers' or 'computer science graduates'. Most of the time when compiling fails it's just because files are "missing" (there is no corruption on the source code) -- the user hasn't properly specified the locations of the header and libraries (shared objects). Now pull your big boy/girl panties up and just do it .... it's easy.
Notes for people clueless about compiling source code for packages in R:
a) pay special attention to the spacing in the above, otherwise it may not work. Do not have any spaces between the = and the variable/file names (e.g. don't try and have in the above PKG_CPPFLAGS ="-I/usr/local/mysql/include/" as it won't work)
b) When compiling, you want to specify the locations of the header files and the library files and this is what the "-I/ .... " and "-L/ ...." are doing. The -I directory specifies the location of the header files, and the -L the location of the library files. The library files also require the -l[name of library] extension (the -l is short for -lib in the library object names).
c) Note that in the directory /usr/local/mysql-5.6.17-osx10.7-x86_64/lib/ I do not see a file called "lmysqlclient", or even "libmysqlclient", but I do see files named (among others) "libmysqlclient.a" and "libmysqlclient.18.dylib". So don't worry about your MySQL installation not being correct if you don't see a file just called "libmysqlclient" in the lib folder.

Can i use HTML::Template in my perl scripts?

I am using godaddy.com for my website hosting
Can i use HTML::Template in my perl scripts? I want to send perl script output to Template file, which internally generate the web page and display on the browser. But while i am using use HTML::Template in my perl script, i am getting error.
Thanks,
Devesh
First, you need to check if HTML::Template is installed on godaddy servers by running the command from this support article:
http://support.godaddy.com/help/article/1488/can-i-add-perl-modules-to-my-hosting-account
If the perl -MFile::Find=find ... call returns HTML::Template in the list, you might use it incorrectly.
If the command does not return the module in the list, you may try to create a local installation of the module (for example, in a lib directory within your web root directory) and include HTML::Template from the local directory. Something like:
BEGIN { push(#INC, '/path/to/the/lib/directory/') };
use strict;
use warnings;
use HTML::Template;