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

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;

Related

Modify an etherpad instance with command line tool

Most instances of Etherpad accept setting the entire file by uploading an HTML file. Is there a way to automate this process with a command line tool such as cURL ?
You can use the HTTP API to create or change the content of a pad. There are several client libraries 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?

Running Ruby script with HTML button?

I have a Ruby script that I run through the Command Line locally. Now I want to run that script through a browser, with a simple HTML button. Is there any way to make a simple HTML page and run the script similar to a JS onclick event? OR will I have to set up a rails environment first?
To run a Ruby script, you need a Ruby interpreter. JavaScript can be run locally by the browser that executes the HTML page, Ruby no.
Therefore, your cannot run the Ruby code directly in the browser. There are several possible solutions.
You can host the Ruby script somewhere, and have the HTML page reference it. If the script is reasonably simple, you can use one of those services that run a Ruby script in a sandbox.
But if it's a Rails app, no way. You need to host it somewhere.
Short answer, you need a server/computer with the Ruby interpreter to execute your script. It can't be executed by the client browser.
There are a few options here. Depending on your use case the most likely two are:
Convert your Ruby script into JavaScript via Opal so that it can run in the browser.
Set up a simple server with Sinatra and run it on a server somewhere, then call it via AJAX.
There are couple of options available for your use case but I would use Sinatra for this. Here is a very simple example for you.
your_file.rb
require 'sinatra'
get '/' do
"<a href='/another-file'> Link to another file </a>"
end
get '/another-file' do
"Today is #{Time.now}"
end
If you do not have sinatra gem installed then please try
gem install sinatra
Once done then you can run your script on your desire port (I'm using 5000)
ruby your_file.rb -p 5000
Now you can browse your simple app at http://localhost:5000. Please checkout sinatra website for complete documentation.

Installing JSON.pm on a web host without shell access

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).