nick13131
Posts: 20
Joined: Mon Nov 10, 2014 3:21 pm

How to run Perl on the Pi

Thu Feb 05, 2015 6:36 pm

How do I create, compile, and run perl scripts on the Pi? Normally, when I type 'perl' at the terminal, all I get is a pause that I have to ctrl-c out of...
It's Pi o'clock somewhere!

User avatar
emgi
Posts: 357
Joined: Thu Nov 07, 2013 4:08 pm
Location: NL

Re: How to run Perl on the Pi

Thu Feb 05, 2015 6:42 pm

You need to specify a program to run:

Code: Select all

perl test01.pl
Or make the program executable by setting the first line like this:

Code: Select all

#!/usr/bin/perl
and make the program executable:

Code: Select all

chmod +x test01.pl
/emgi

nick13131
Posts: 20
Joined: Mon Nov 10, 2014 3:21 pm

Re: How to run Perl on the Pi

Thu Feb 05, 2015 6:48 pm

Thank you!
It's Pi o'clock somewhere!

User avatar
emgi
Posts: 357
Joined: Thu Nov 07, 2013 4:08 pm
Location: NL

Re: How to run Perl on the Pi

Thu Feb 05, 2015 7:04 pm

Glad to be of help. If you have any more questions, just ask.
No reason why but perl seems to be an oddball on the Pi.
Still everything perl works seamless so I don't get it. Probably people think Python is easier. :?:

I'm quite happy with perl; it works cross-platform and the integration with sqlite & mysql is very good.
That's really all you need to create an interesting website and many other coding projects.

/emgi

User avatar
DougieLawson
Posts: 34361
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: How to run Perl on the Pi

Thu Feb 05, 2015 9:42 pm

I'm still a perl monger on my RPis, it's an ugly language but it's less ugly than python because blocks of code have those nice familiar { & } wrapped round them.

I've always liked Perl's principle of least surprise.
Note:Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

User avatar
emgi
Posts: 357
Joined: Thu Nov 07, 2013 4:08 pm
Location: NL

Re: How to run Perl on the Pi

Thu Feb 05, 2015 9:54 pm

DougieLawson wrote:I'm still a perl monger on my RPis
Good to know that Dougie, I had already placed you in the Python camp.

/emgi

User avatar
DougieLawson
Posts: 34361
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: How to run Perl on the Pi

Thu Feb 05, 2015 10:12 pm

emgi wrote: I had already placed you in the Python camp.
How very dare you?

There are so many things wrong with python. The primary one being the abject confusion between 2.7 and 3.2. Why have two versions, why have two incompatible versions.

The other egregious badness with python is left hand white space having a syntactical value. There's nothing wrong with { & } to delimit code blocks.

And finally, where's the bleeding "select, case, otherwise" language element. Don't we all love those nested IFs with a new level of left indent for each condition, that makes for nice readable code, NOT.
Note:Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

User avatar
emgi
Posts: 357
Joined: Thu Nov 07, 2013 4:08 pm
Location: NL

Re: How to run Perl on the Pi

Fri Feb 06, 2015 8:06 am

DougieLawson wrote:
emgi wrote: I had already placed you in the Python camp.
How very dare you?
Simple: I've seen quite a few code samples from you in Python but none using Perl. 8-)
Admittedly I didn't check all your posts :mrgreen: but I don't think I'm far from the truth.

And even if you are as much of a perl monger as myself, Perl IMHO still remains an oddball on the RPi.
Most importantly, there is a Python section on the forum but not a Perl one. Why would that be if Perl was really popular?

Not that it is needed; there are already more than enough good resources on Perl to be found on the web.
Considering that, and the fact that Perl on the RPi simply works (fast & stable) I am somewhat surprised about the apparent unfamiliarity of Pi users with this language.

/emgi

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: How to run Perl on the Pi

Fri Feb 06, 2015 1:04 pm

i take a look here http://perl-begin.org/uses/GUI/
and would like to ask you what is installed on RPI
or whats best to start?

User avatar
DougieLawson
Posts: 34361
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: How to run Perl on the Pi

Fri Feb 06, 2015 1:33 pm

The reason for all of that python is that's the language Eben Upton picked for his project to teach computing to the World. IMNHO, he's wrong. Even Java is better because it has nice shiny { & } round code blocks.

Most of my code is little snippets to demonstrate something and not full scale programs.

My problem is picking which of the 25 or more languages to use when I write code. The choice is usually based on whether there's a ready built library for the stuff I'm doing. COBOL could be the future on the RPi.
Note:Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: How to run Perl on the Pi

Fri Feb 06, 2015 2:06 pm

very good, teach me COBOL

i found that perl comes NOT with GTK2,
sudo apt-get install libgtk2-perl
see more http://kll.engineering-news.org/kllfusi ... #example4c
Last edited by KLL on Sat Feb 07, 2015 5:47 am, edited 1 time in total.

User avatar
emgi
Posts: 357
Joined: Thu Nov 07, 2013 4:08 pm
Location: NL

Re: How to run Perl on the Pi

Fri Feb 06, 2015 2:33 pm

KLL wrote:i take a look here http://perl-begin.org/uses/GUI/
and would like to ask you what is installed on RPI
or whats best to start?
I don't use a gui on the Pi to do Perl. Most of the coding is done on my Win7 laptop.
My projects are managed in an editor. Check: www.pspad.com
When ready, the programs (scripts actually) are copied via nfs or samba shares or simply cut/paste into vi.
So on the Pi, I only have Perl itself and vi. Needless to say I'm running exclusively on the cli via putty.


/emgi

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: How to run Perl on the Pi

Fri Feb 06, 2015 2:55 pm

emgi wrote:Most of the coding is done on my Win7 laptop.
My projects are managed in an editor. Check: http://www.pspad.com
When ready, the programs (scripts actually) are copied via nfs or samba shares or simply cut/paste into vi.
/emgi
i play with it some years ago, but i think you would love the http://notepad-plus-plus.org/ too where you can edit the files in RPI directly ( nppFTP window )
only for python must adjust the TAB --> space setting or get trouble with indentation!

User avatar
DougieLawson
Posts: 34361
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: How to run Perl on the Pi

Fri Feb 06, 2015 3:05 pm

KLL wrote:very good, teach me COBOL
I hope you like writing lots of words to say very little about what you'd like your program to do.

Code: Select all

000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID.     HELLOW.
000300
000400*
000500 ENVIRONMENT DIVISION.
000600 CONFIGURATION SECTION.
000700 SOURCE-COMPUTER. S/390.
000800 OBJECT-COMPUTER. S/390.
000900
001000 DATA DIVISION.
001100 FILE SECTION.
001200
100000 PROCEDURE DIVISION.
100100
100200 HELLO-WORLD SECTION.
100300 BEGIN.
100400     DISPLAY "Hello world!" UPON CONSOLE.
100500*Note: Don't use STOP RUN, it can have unexpected effects
100600     GOBACK.
100700 HELLO-WORLD-EXIT.
100800     EXIT.
The full stops are crucial to syntax. You can have line numbers in cols 1 to 6 and card deck sequence numbers in colums 72 to 80. Continuation cards have a - in column seven, comments have an * in column 7.

There is a COBOL to Java compiler available for the Raspberry Pi, but it didn't work when I tried it and I wasn't bored enough to try to shoot the bugs. Remember "COBOL" rhymes with "snowball".
Note:Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: How to run Perl on the Pi

Fri Feb 06, 2015 4:18 pm

i think you miss
borland turbo pascal
very much, me too

User avatar
DougieLawson
Posts: 34361
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: How to run Perl on the Pi

Fri Feb 06, 2015 5:22 pm

KLL wrote:i think you miss
borland turbo pascal
very much, me too
I wrote a mainframe Pascal program that should have read some data from a DL/1 hierarchical database. That program failed (not in my code) in IBM's database code first time I ran it. When I traced the bug it was glaringly obvious what was wrong and it was clear the code had never been tested (not even by IBM). I was definitely the very first (and probably last) person to ever run a Pascal & DL/1 program.

I have never been near that language ever since and that was probably 25 years ago.
Note:Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

User avatar
piglet
Posts: 883
Joined: Sat Aug 27, 2011 1:16 pm

Re: How to run Perl on the Pi

Fri Feb 06, 2015 6:03 pm

Perl <3.

I love the language. You can write lovely nice clear well structured and documented code (I try to do this) - however I do tend to find that a lot of other people's code is incomprehensible. Python runs too slowly when processing large text files to get much of a look-in.

This is my favourite Perl script of all time. It's safe to run. Stick it in a file and run it perl filename::

Code: Select all

    ''=~(        '(?{'        .('`'        |'%')        .('['        ^'-')
    .('`'        |'!')        .('`'        |',')        .'"'.        '\\$'
    .'=='        .('['        ^'+')        .('`'        |'/')        .('['
    ^'+')        .'||'        .(';'        &'=')        .(';'        &'=')
    .';-'        .'-'.        '\\$'        .'=;'        .('['        ^'(')
    .('['        ^'.')        .('`'        |'"')        .('!'        ^'+')
   .'_\\{'      .'(\\$'      .';=('.      '\\$=|'      ."\|".(      '`'^'.'
  ).(('`')|    '/').').'    .'\\"'.+(    '{'^'[').    ('`'|'"')    .('`'|'/'
 ).('['^'/')  .('['^'/').  ('`'|',').(  '`'|('%')).  '\\".\\"'.(  '['^('(')).
 '\\"'.('['^  '#').'!!--'  .'\\$=.\\"'  .('{'^'[').  ('`'|'/').(  '`'|"\&").(
 '{'^"\[").(  '`'|"\"").(  '`'|"\%").(  '`'|"\%").(  '['^(')')).  '\\").\\"'.
 ('{'^'[').(  '`'|"\/").(  '`'|"\.").(  '{'^"\[").(  '['^"\/").(  '`'|"\(").(
 '`'|"\%").(  '{'^"\[").(  '['^"\,").(  '`'|"\!").(  '`'|"\,").(  '`'|(',')).
 '\\"\\}'.+(  '['^"\+").(  '['^"\)").(  '`'|"\)").(  '`'|"\.").(  '['^('/')).
 '+_,\\",'.(  '{'^('[')).  ('\\$;!').(  '!'^"\+").(  '{'^"\/").(  '`'|"\!").(
 '`'|"\+").(  '`'|"\%").(  '{'^"\[").(  '`'|"\/").(  '`'|"\.").(  '`'|"\%").(
 '{'^"\[").(  '`'|"\$").(  '`'|"\/").(  '['^"\,").(  '`'|('.')).  ','.(('{')^
 '[').("\["^  '+').("\`"|  '!').("\["^  '(').("\["^  '(').("\{"^  '[').("\`"|
 ')').("\["^  '/').("\{"^  '[').("\`"|  '!').("\["^  ')').("\`"|  '/').("\["^
 '.').("\`"|  '.').("\`"|  '$')."\,".(  '!'^('+')).  '\\",_,\\"'  .'!'.("\!"^
 '+').("\!"^  '+').'\\"'.  ('['^',').(  '`'|"\(").(  '`'|"\)").(  '`'|"\,").(
 '`'|('%')).  '++\\$="})'  );$:=('.')^  '~';$~='@'|  '(';$^=')'^  '[';$/='`';

User avatar
emgi
Posts: 357
Joined: Thu Nov 07, 2013 4:08 pm
Location: NL

Re: How to run Perl on the Pi

Fri Feb 06, 2015 8:54 pm

I didn't know that one.
Amazing!

dmu1957
Posts: 1
Joined: Sun May 31, 2015 5:14 am

Re: How to run Perl on the Pi

Sun May 31, 2015 5:33 am

I have perl scripts and modules that I have written for 2003Server. I want to port them to the RPI. But they don't execute in the browser. How do you make them behave as they do in server 2003? At first, I put them in usr/lib/cgi-bin but that didn't work. So i triedi where I like them in /var/www/pl

When run in a terminal, The complaint is cant locate Cart:Lines.pm

When run in a browser, I get a message box asking what to open it with.

In server 2003 you have to configure the directory as executable and put the pm in the library

rotwang
Posts: 240
Joined: Sat Dec 07, 2013 1:12 pm

Re: How to run Perl on the Pi

Sun May 31, 2015 1:27 pm

DougieLawson wrote:
KLL wrote:very good, teach me COBOL
I hope you like writing lots of words to say very little about what you'd like your program to do.

Code: Select all

000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID.     HELLOW.
000300
000400*
000500 ENVIRONMENT DIVISION.
000600 CONFIGURATION SECTION.
000700 SOURCE-COMPUTER. S/390.
000800 OBJECT-COMPUTER. S/390.
000900
001000 DATA DIVISION.
001100 FILE SECTION.
001200
100000 PROCEDURE DIVISION.
100100
100200 HELLO-WORLD SECTION.
100300 BEGIN.
100400     DISPLAY "Hello world!" UPON CONSOLE.
100500*Note: Don't use STOP RUN, it can have unexpected effects
100600     GOBACK.
100700 HELLO-WORLD-EXIT.
100800     EXIT.
The full stops are crucial to syntax. You can have line numbers in cols 1 to 6 and card deck sequence numbers in colums 72 to 80. Continuation cards have a - in column seven, comments have an * in column 7.

There is a COBOL to Java compiler available for the Raspberry Pi, but it didn't work when I tried it and I wasn't bored enough to try to shoot the bugs. Remember "COBOL" rhymes with "snowball".
Nice to see some well written COBOL again. Everyone seems to overlook the fact that a properly laid out set of DIVISIONS gives you more information than most peoples idea of documentation. A classic example of one person doing it once, instead of countless people repeating the exercise.
As for Pascal, it was one of the best teaching languages, right up to the moment when some damn fool wrote a compiler for it. Then the whole thing went to hell in a hand-cart.

Return to “Beginners”