HOWTO Use Perl on Puppy Linux Systems

How to do things, solutions, recipes, tutorials
Post Reply
Message
Author
humanise
Posts: 15
Joined: Fri 22 Apr 2011, 10:06
Location: Melbourne, Australia
Contact:

HOWTO Use Perl on Puppy Linux Systems

#1 Post by humanise »

Please review and correct this HOWTO as needs be. It is designed to be both suitable for newbies as well as detailed. As a consequence it is likely to be too long winded for the more experienced but the detail given will still likely provide some useful information.

HOWTO Use Perl on Puppy Linux Systems


Today's Puppy Linux systems contain a copy of Perl with the base operating system. At the time of writing this, I'm using Puppy 5.2.5. Perl has been in the main Puppy versions since about middle of 2006 onwards. Consequently, for most Puppy Linux systems you don't need to add anything to your operating system to write and run a standard Perl program so long as the Perl script doesn't use Perl's CPAN libraries.

From a Linux command console (such as the urxvt terminal emulator under the Utility menu) the command

Code: Select all

perl -v
Will tell you the current version of your Perl if you have Perl installed.

The command

Code: Select all

which perl
tells you where the Perl interpreter will execute from. Currently running this gives a response of the following:
/usr/bin/perl
This should be used on the first line of your Perl scripts with a Shebang (#!) placed before it to tell the system what compiler you are wanting to use. Many people place a space then a -w after it. This is the equivalent of adding the directive 'use warnings'. It is recommended to always add this directive and always add the 'use strict' directive. Consequently, the first line of your Perl script should have the following:

Code: Select all

#!/usr/bin/perl  -w
My helloworld.pl file contains the following lines:

Code: Select all

#!/usr/bin/perl  -w
use strict;
print "Hello World \n";
The Perl script files should have their flags set so that they are executable. From a Linux command console, after doing a cd to the directory containing the script, the scripts should be then executable by typing ./ following by the name of the script. For example:

Code: Select all

 ./helloworld.pl

For Linux you need the ./ in front of the file name unless the "." has been placed into your PATH variable. If you get the following style of error:
bash: ./helloworld.pl: Permission denied

then you probably haven't set the execute flag for this file. Note that with many puppy installations that share disk space with Microsoft Windows, the directories within /mnt/home or sda1 do not allow you to change the flags. In this area of the file system, Puppy simply assumes that all text files have the execute flags set. You only have to worry about the file's flags when the file is within Puppy's own file system such as files within the /root directory.

If you get a response of the following form:
bash: ./helloworld.pl: /usr/bin/perl^M: bad interpreter: No such file or directory
or (if your script has the directive 'use warnings') just the following:
: No such file or directory
then the script file is probably formatted as an MSDOS file. You need to convert the line endings to Linux format. This problem occurs with Bash scripts also.

Note that with errors that relate to the filesystem such as 'No such file or directory', it can help to temporally comment out the use warnings directive to see if you get more helpful information from Bash.

From a Linux command console, after doing a cd to the directory containing the script, you can also execute the Perl script by a command in the following form:

Code: Select all

 perl  helloworld.pl
This will work in a number of cases such as using MSDOS files where just typing ./helloworld.pl won't work.

By creating a small shell script you can have your perl script run from a single click without having to open a command console. Further, if you drag the shell script to the desktop you will create a shortcut icon on the desktop. Assume the above helloworld.pl file is placed in your ~/my-applications directory. In this case you can create a text file with the following lines:

Code: Select all

#!/bin/sh
tail -n +4 $0  > /tmp/myscript.txt
exec rxvt -e sh /tmp/myscript.txt
perl ~/my-applications/helloworld.pl
read
Change the fourth line so that it refers to your Perl script. You can save this shell script in a file named HelloWorld (or named anything else you like). Ensure that its flags are also set for it to be executable.

Click it from ROX-Filer or other file explorer program and it will run the helloworld.pl Perl script leaving a terminal window open with the output. Alternatively, drag the shell script to the desktop and you will create a shortcut icon on the desktop. If you right click this icon and select 'File <filename>' and then 'set icon...', you can setup your own image for this icon or for all icons for shell scripts. Also, if you right click this icon and select 'Edit Item', you can assign it a short cut key combination.

If you have an application where you don't need the terminal window left open then leave off the 'read' line in the above shell script. Special note for this shell script: Don't leave any blank lines within the first 3 lines of this script. You can get more information on this script from the following address:

http://www.murga-linux.com/puppy/viewtopic.php?t=59322

Geany, the default text editor in the current Puppy, will recognize that a script is in Perl if the filename ends with .pl or if the first line starts with #!/usr/bin/perl Geany will then provide color coding to give Perl syntax highlighting. For the editing of Perl scripts it provides a number of useful features such as auto-indentation, go to tag definition and autocompletion. You can also directly run the Perl script from within Geany by selecting 'Execute' from the toolbar or from the Build menu or by depressing the F5 key.

You can also get Geany to automatically set the execute flag on any Perl script that it executes. To do this, first load a script that it recognizes as being Perl. Then select the 'Set Build Commands' from the Build menu. Under 'Execute Commands' to the right of the Execute Button you should see Perl "%f". Change this to the following and click the OK button.

Code: Select all

chmod a+x "%f" && perl "%f"

Creating websites is one of the common uses for Perl. Consequently, it is worth pointing out a problem with the use of some Puppy's for website design. When Puppy uses Microsoft Windows filesystems, such as a Frugal shared disk installation, it does a fudge for the file permission flags. All permissions are given for those files. When you use an ftp client program such as gFTP to upload these files to a web server, those permission flags are normally copied to the web server with the file. These can be difficult to change on the server and this poses a security risk. I suggest that you shift the files to one of the subdirectories of /root before working on the files and before doing any uploads. This way you can keep an eye on and modify appropriately the permission flags before the files are uploaded. This applies to all files used on the web server, not just Perl scripts.

If you try to run a script that requires any CPAN library modules that you haven't installed then you will get an error message that starts with something like the following:
Can't locate MODNAME/Submod.pm in @INC (@INC contains: ...
The error message should show the line of the Perl script that caused the problem. This line will probably have a 'use' statement something like the following example:

Code: Select all

use LWP::UserAgent;
You need to download, compile and install the missing modules (as used in the 'use' statement) from the "Comprehensive Perl Archive Network" (ie. CPAN) or mirror thereof which is available over the internet. It is possible to manually download and install the needed modules but it is generally better to first install the CPAN perl module into your Perl. This module automates the download and installation. This includes finding and automatically installing any needed dependencies for the module.

Steps for this are as follows:

As most of the modules you download require compilation (from C or C++ source) you first need to update your copy of Puppy to include the developers compilers. (ie _devx_)

You may be able to do this with the quickpet program under the SFS-Get Tab

Otherwise, you can do it manually. For this you need to download the current _devx_ sfs file for your version of puppy (called lupu_devx_525.sfs for Puppy 5.2.5) into the installation and configure the boot manager to load it at startup. For live CD and Frugal installs the configure is as follows:

menu >>system >>bootmanager configure bootup >>>> Choose which extra sfs to load at bootup

Note: In a full hard drive partition installation (ext2, ext3 or ext4) there is a different means of installing the devx sfs file. See the following for more info:

http://puppylinux.com/development/compileapps.htm

The CPAN perl module looks for a large number of programs when it installs itself. When it doesn't find some of these it often has an alternative so getting errors relating to these doesn't always mean it won't work. One program it likes to use is the Lynx text based web browser. You are best to install this first. A puppy .pet copy can be obtained from

http://puppylinux.org/wikka/Lynx

Download the .pet package, click on it and it will install itself. With my installation of the CPAN perl module, it didn't find ncftpget, ftp or applypatch programs but it is working alright without them. Now you can install the CPAN perl module.

With Puppy, you are already running as user root so you don't need to do a 'su root' as you would with other Unix Operating Systems. From a Linux command console just type the following.

Code: Select all

perl -MCPAN -e shell

The first time it is run, it will ask you a bunch of configuration questions. For most people all of them can be answered with the default value (press <return>) including allowing it to install automatically. Don't be too concerned with errors relating to not being able to find things.

When finished it should come up with the cpan shell prompt as following:

Code: Select all

cpan>

The next time you run cpan, it will go directly to the cpan shell prompt. From the cpan shell enter h for help or q for quit back to the Linux command line.

You may want to make sure you have the latest and greatest CPAN perl module with all the trimmings. To do this, at the cpan shell prompt type the following command:

Code: Select all

cpan> install Bundle::CPAN

Again, it will ask you many questions, which can normally be answered with the default value (press <return>) including allowing it to install automatically. Don't be too concerned with errors but you need to stay with it to keep pressing the return key when it needs it. It takes a long time to install. It keeps trying to use modules it hasn't installed yet but it will come back to these later. When finished you can quickly reload it as follows:

Code: Select all

cpan> reload cpan
From the cpan command line you should be able to install any perl module with a single command. A standard install of a module is done with the standard install command. An example may be as follows:

Code: Select all

cpan> install HTTP::Request

If it is already installed, it will tell you. In many cases you will want the complete bundle relating to the module. An example of a typical bundle install is as follows:

Code: Select all

cpan> install Bundle::LWP
If cpan encounters any problems, it will not install the module. If you wish to force the install, then use the "force" command as in the following example:

Code: Select all

cpan> force install Tk
Actually, the Tk module is a bad example as, without the force, it installed fine on my Puppy system. The Tk module provides a set of tools (widgets etc) to create Graphical User Interfaces (GUI) for your program. This is the same Tk as used in Tcl/Tk.

After quiting the CPAN module (with q) if you later wish to install an extra module you can simple re-enter CPAN again using the 'perl -MCPAN -e shell' command. It should just start without doing another install.

Installing a Perl module manually can be required in some instances. In this case, save it somewhere. From a command line change directory to where you saved it and enter commands of the following form (assuming the file is called Abc999.999.tar.gz).

Code: Select all

gunzip Abc999.999.tar.gz 
tar -xvf Abc999.999.tar 
cd Abc999.999 
perl Makefile.PL 
make 
make test 
make install 
The last line of this (make install) requires root privileges but you already have these with Puppy.

Some of the above information came from the book "Impatient Perl" by Greg London. This is a good book for getting up and running with Perl in a short time. The book is more suited for someone who already knows how to program in other languages. It is freely distributed under the GNU Free Documentation License. You can download it from the following website:

http://www.greglondon.com/iperl/index.htm

A good Tutorial on the Tk module can be downloaded from the following website:

http://www.bin-co.com/perl/

From a Linux command console you can also use the man command to get information about or learn Perl. With the current Puppy, this is supplied from the internet into your browser. The Perl man manual has been split up into a large number of sections. Type 'man perl' and it lists the sections such as perlintro for an introduction to Perl or perlsyn for the Perl syntax. To get each section just type 'man' in front of the name of the section. For example, to get the Perl syntax type 'man perlsyn'.

Perl is a computer language that is mentioned in a very high number of computer job vacancies. While it is a good language, the real advantage of it probably lies more with the size and strength of the CPAN Archive of modules rather than the language itself. Given the high number of jobs in Perl, it is well worth spending some time learning the language.

Hope this is helpful
Ken Dawber

SimpleWater
Posts: 94
Joined: Tue 19 Apr 2011, 11:53

#2 Post by SimpleWater »

Here is the link for full installs:
http://distro.ibiblio.org/pub/linux/dis ... vx_525.sfs
(installing the devx from the quickpet did not work for me. Save yourself the trouble and download it directly.)

So the solutions here worked for me so thanks. I just started to learn perl, like today, and some of the more recent tutorials used "say" instead of "print". I would get an error message when trying to activate it using
"use feature ':5.10';"
error message "can't locate feature.pm in .......blah blah
Interesting enough, either installing the devx or installing linx did the trick. Glad i tested it out before i downloaded the module, i don't i need it anymore. Now i can write:

say "Howdy Partner!"
instead of:
print "Howdy Partner!\n"

hopefully no more troubles or features missing from now on, though i still can't access the perl documentations using

Code: Select all

perldoc
i get: You need to install the perl-doc package to use this program

edit: i tried man perl as well, and no manual entry for perl

User avatar
GustavoYz
Posts: 883
Joined: Wed 07 Jul 2010, 05:11
Location: .ar

Let's bring this post to life again :)

#3 Post by GustavoYz »

:arrow: General introduction:

Code: Select all

perldoc perlintro
:arrow: Syntax intro:

Code: Select all

 perldoc perlsyn
:arrow: You can get the whole official documentation as html only or html+pdf files in this site http://perldoc.perl.org/. Check you number version first.

:arrow: If your Puppy has man on it, Debain repo has a "perldoc.deb" with man pages waiting for you (check the Perl version, Lenny package is the same perlversion that Quirky 1.2 and some Puppies 4xx).
Perl man pages are exactly the same information that perldoc's pod files; in fact, there are all made with 'pod2man' program.

:arrow: A really good idea is install the module "Pod::Pdf" from CPAN, to create pdf files of the most used docs (like the perlfaqs).
With this, you can do something like:

Code: Select all

pod2pdf `perldoc -l perfaq`
to create a pdf file from some pod (format of the perl's help files).
Then grab the pdf file:

Code: Select all

cd `perldoc -l perlfaq`
:arrow: For info in a function, use this command:

Code: Select all

perldoc -f open
:arrow: To see what modules you've added to your Perl so far, check this:

Code: Select all

perldoc perllocal

:arrow: To debug, i recommend to 'use diagnostics' (see `perldoc diagnostics`). But read the doc:

Code: Select all

perldoc perldebtut
:arrow: "$| = 1" means unbuffered, this can speed some tasks, and you can always set it to 0 again (it can mess some things too).

:arrow: Regex resources.
Introductory tutorial:

Code: Select all

perldoc perlre

Code: Select all

perldoc perlrequick
A good, detailed tutorial:

Code: Select all

perldoc perlretut
How Perl regex works?

Code: Select all

perldoc perlreguts
References on meanings of operators, classes, context...

Code: Select all

perldoc perlreref
:arrow: Perl cames with a lot of modules and pragmas, you can get a list of those using:

Code: Select all

corelist -v 5.10.1
Replace that number for the only of your version, as `perl -v` shows.

:arrow: This one covers an ideal installation, not the real one, but still is useful:

Code: Select all

perldoc perlmodlib
.
Also gives a list of CPAN mirrors, need to pass some to configure cpan app itself the very first time.

:arrow: Lack of memory? Cheat! 8)

Code: Select all

perldoc perlcheat

sayhello_to_the_world
Posts: 77
Joined: Mon 24 Dec 2012, 15:19

#4 Post by sayhello_to_the_world »

hello dear folks


i want to run puppy with

perl and addtional to the general perl-packages with

a. mozrepl and
b. www mechanize firefox

is this doable!?

can this be done with a live-version of puppy!?

love to hear from you

grreetings

User avatar
GustavoYz
Posts: 883
Joined: Wed 07 Jul 2010, 05:11
Location: .ar

#5 Post by GustavoYz »

I never installed mozrepl, but guess you can try. Firefox has been always around.
To use Perl in any Puppy, is recommended to have the devxxx.sfs up and running, as it has an almost full Perl (the lacking core modules are in it). To install cpan modules in Perl, I'd use

Code: Select all

cpanp i WWW::Mechanize
(It will take some time if is the first time you use "App::cpanp".)
Be sure your pupsave has space and if it asks you about installing missing modules, choose "Yes to All".

vanchutr
Posts: 438
Joined: Sat 05 Aug 2006, 12:04

#6 Post by vanchutr »

to: sayhello_to_the_world
Download "precise-3.8.3.1-SCSI.iso". There are perl and python were built in.

sayhello_to_the_world
Posts: 77
Joined: Mon 24 Dec 2012, 15:19

#7 Post by sayhello_to_the_world »

hello you both - good day dear gustavo and vanchutr



many many thanks for the quick reply.
vanchutr wrote:to: sayhello_to_the_world
Download "precise-3.8.3.1-SCSI.iso". There are perl and python were built in.
great to hear that.

i will tray out all your advices

greetings
say

Post Reply