Run perl online - perl

I want to run a Perl script online, but I don't know how.
In PHP you need to start with <?php, so do you have to start with something like that in Perl?
And does Apache automatically recognize Perl? Or do I have to upload Perl and let it point to it using #!/path/to/perl?
Can I use print() to display HTML?

In PHP you need to start with <?php, so do you have to start with something like that in Perl?
There are frameworks (such as Mason) which work like that, but it is more typical to have a standard Perl program which outputs the page.
And does Apache automatically recognize Perl?
Apache doesn't automatically recognise any kind of server side programming.
Or do I have to upload Perl and let it point to it using #!/path/to/perl?
You would need to have Perl installed on the server. You would generally start a script that way (but not necessarily, e.g. if you were using mod_perl), but would have to configure the server to recognise it as an executable and run it (just as you have to configure the server to recognise files ending with .php as scripts to run with PHP).
Can I use print() to display HTML?
Yes.
You should probably start by looking at the question Web Programming For The Non-Web Programmer (in Perl).

Must you use Apache? If not here is an alternative to consider.
I have found that the built-in servers and templating engine in the Mojolicious framework work very naturally for inline Perl within HTML. The tags are of the form <%== but work the same way. Also it has good documentation and examples to get you going.
Edit: It seems that there are ways to use Apache with Mojolicious too, see http://search.cpan.org/perldoc?Mojolicious::Guides::Cookbook, though the built-in servers have worked well for me, with FAR less (ie no) configuration.

Apache HTTP doesn't automatically understand Perl or PHP for that matter. For PHP to work, you have to have the Apache httpd module called something like mod_php.so or libphp5.so installed. However, since many websites use PHP in this manner, this Apache httpd module is normally installed.
Just as you need mod_php in order to use PHP in Apache's httpd web server, you need to do is make sure your web server is using mod_perl if you want to use Perl in a similar manner.
You'll need to build and install mod_perl which can be tricky -- especially if you don't control the machine the server is on.
The other way to use Perl is to use what's known as CGI-Perl. This is much easier to setup, but it is also much more dangerous since it can lead to someone being able to run unauthorized programs on your Apache httpd server.
In this case, you need to set up a CGI-BIN directory, and configure Apache httpd. This is fairly simple. Once you do that, you put all of your Perl scripts into the _CGI_BIN_ directory. In this case, your Perl scripts will have to handle all of the communication between your web server and the web client and handle all displays. Fortunately, it's not too difficult in perl since Perl gives you the basic modules to do this.

Related

Unable to call cURL from perl in Unix

My project wants to download files on Unix AIX from the AWS platform. I am trying to call cURL from within Perl script to server this purpose.
I am getting an error
Can't locate LWP/Curl.pm in #INC. Haven't been able to find libcurl.pm and curl.pm in respective directory of perl installation.
The version of Perl being used here is 5.8.8. I have read about this error and found that it requires libcurl.pm (7.10.8 version) and curl.pm modules installed in Perl's module library.
Going forward there is a plan to use cURL in combination with FTPS in order to download files from AWS. I have also read WWW library should be used instead of LWP from cpan.search.org. Can you advise which is better?
Also, if you could list the prerequisites of using cURL from within Perl script please?
The LWP::Curl module needs to be installed
It doesn't require libcurl.pm or curl.pm; indeed, there are no such modules
It does require WWW::Curl::Easy, but that will ordinarily be installed automatically when you install LWP::Curl
There are very many WWW modules and I can't tell which one you mean
I would normally recommend the regular LWP as it is the "standard" way of writing an internet client, but I don't believe it supports FTPS, so LWP::Curl should do fine
To install the LWP::Curl Perl library, you need to have libcurl and the C header files on your system. The WWW::Curl::Easy module will build against those, and the build will fail if you don't have them
That is all you need
You may want to consider LWP::Protocol::Net::Curl, which is very similar to LWP::Curl but it is a completely separate module by a different author and with different dependencies. It hasn't been updated as recently as LWP::Curl, but it is designed and tested as another LWP:;Protocol plug-in which can replace the standard protocols leaving LWP to work as normal. LWP::Curl doesn't seem to be quite as compatible

which mod_perl for windows 7 x86, apache 2.2.25, perl 5.16?

the title perty much says it all. running;
windows 7 on x86 mother board, with apache 2.2.25 and perl 5.16.
I can't seem to find aggrenment on witch mod_perl to use. AND,
from the docs i've seen the problem will be getting it and
configuring. pointers of detailed instructions will be best.
and i see another problem coming before i get there and i've looked around.
how to get windows 7 iis permission to run .cgi and .pl script.
what i've read start will, run inetmgr.exe.. when i try to run inetmgr.exe the system
tell me 'can't find', are the docs wrong, my windows admin file broken ???
please respond to grumpyoldphuker#gmail.com.
You don't need Apache and mod_perl if you just need to run CGI scripts under IIS on Windows. Perl will be able to do that by itself, as long as you have IIS configured to run CGI scripts correctly.
Otherwise, you might want to take a look at http://plackperl.org/ instead, for the "modern" way to run Perl-based web applications. You can likely use IIS as a front-end proxy in front of your Plack server process.

Perl. Fetching file from remote server, only core modules

I need help: is there a way to fetch a file from the remote server using only core modules of perl 5.8.8? File::Fetch became core module only from 5.9.
This comes up all the time. Take a look at the classic yes, even you can use CPAN. If you have the ability to create and run a Perl script, then you also have the ability to put a module in your local directory and use it. The requirement to use only core modules is entirely artificial.
In your case, LWP::Simple's getstore() function will do what you want. While it is technically not core, LWP::Simple is included by default with many Perl distributions. You may well already have it.
Update: so, you want to do this on 1000 servers? No need to manually install the module on each server. Use CPAN programmatically to download and install the module(s) you need (some tweaking will be needed to get CPAN to install it locally rather than in the root module library). Also Leon Timmermans's suggestion of fatpacking the module is another option.
If you really don't want to do it this way, then basically the answer is no: there is no simple way to fetch a remote file via HTTP using neither the appropriate modules, nor a system command (I didn't consider writing your own HTTP client to be a simple method, but that's fine if it works for you).
The only other potential solution I see would be a different approach to your problem, such as:
Using a script in a single location to get the file, then distribute
it to all 1000 servers via FTP.
Or, putting the file on an FTP server, then using a simple Perl
script on each server to fetch it via FTP.
As Dan already said, yes, even you can use CPAN. One approach his link doesn't mention is writing it as a normal CPAN-using distribution, and then fatpack it. Fatpacker combines a script with all its (pure-perl) dependencies, creating a single easy to distribute file.
You could use:
my $wgetoutput = `wget "$myFileToGet"`;
Stuff in backticks (`) will be given to the default shell, so you can call whatever you want (and are allowed) there.
Caveat: $myFileToGet could have stuff like "&& rm -rf *" in it, so dont forget to sanitize!

Perl Dancer on Apache server using Plack::Runner

I have a Perl Dancer web app which I would like to run on an apache server (on centos 6).
I put at the webapp's rootdir a sym link (index.html) to the public/dispatch.cgi script which uses the Pluck::Runner module.
The problem is when loading the page, it can't find a needed files (such as the sqlite file), in fact the routing is messed up since it looks for routing at $appname/index.pl/blabla... instead of $appname/blabla...
I think some kind of apache directive or rule is needed here but I don't these well enough.
I hope some one could help me solving this issue.
Thanks in advanced.
Roy.
It would help if you would provide your apache (vhost) configuration.
You should read the section 'Running as a cgi-script (or fast-cgi)' of Dancer deployment, because that document presents a lot differnt ways to deploy your Dancer application.
I like to use starman behind Apache as proxy. In the Perl Advent Calender 2010 you find a description how to do that.
Starman is fast for the dynamic part and apache perfect for static files and routing.

Patching a perl cgi web application

I've written a web cgi application in perl and before I start to distribute it to clients, I'd like to provide an option for future updates.
I would like to know what are the standard approaches for that using free Linux tools.
It is OK for the server to be stopped during updating.
Thank you,
Spasski
If you have separated code from configuration and data, then the easiest way is to tar/zip the new files and unpack them onto the existing installation. If you need to update the data files, then you could include a script that makes the necessary changes.
Take a look at th bugzilla upgrade guide. I've used this process many times without a hitch.
http://www.bugzilla.org/docs/tip/en/html/upgrade.html