Perl help

Post Reply
User avatar
thehemulen
Posts: 428
Joined: Fri Aug 27, 2004 3:26 pm
Location: cyberspace. Berlin
Contact:

Perl help

Post by thehemulen » Mon Aug 13, 2007 10:18 pm

hello friendly forest geeks!

can anyone gimme some tips on learning Perl? i need it for a project ive been asked to help on... have a good beginners tutorial from perl.com but i still dont have anyway to run Perl scripts...? i need an interpreter? apparently there should be one pre-installed on my mac os x, but i dont find nothing, tried to install something called ActivePerl but i cant find the .app although its said installation successful... oh dear, pogo/swithun/chombee - if any you guys are around end of august when i come for connect festival, i need to talk!

stay cool,

Drock
"If something is boring after two minutes, try it for four. If still boring, then eight. Then sixteen. Then thirty-two. Eventually one discovers that it is not boring at all." --John Cage.

swithun
Posts: 2683
Joined: Wed Mar 29, 2006 12:24 pm

Post by swithun » Mon Aug 13, 2007 10:33 pm

It is probably easiest if you open up a terminal and run the script from there. I've never used OS X, so I'm not sure about directory layout. But if you save the script in your home directory, you should be able to find it from inside the terminal.

I'm going to France on the 29th, but if you are here before then, I can help out.

User avatar
thehemulen
Posts: 428
Joined: Fri Aug 27, 2004 3:26 pm
Location: cyberspace. Berlin
Contact:

Post by thehemulen » Mon Aug 13, 2007 10:51 pm

yeah, right - i'm in terminal...trying to run very simple things..just getting "No such file or directory"....ach, i'll just keep banging my head against the cyber wall - im sure this is something one has to do alone. but arent i too old to be getting into this shit?

have fun in france swithers!

big up, Drock
"If something is boring after two minutes, try it for four. If still boring, then eight. Then sixteen. Then thirty-two. Eventually one discovers that it is not boring at all." --John Cage.

User avatar
Martin
Posts: 1084
Joined: Mon Sep 11, 2006 1:35 pm

Post by Martin » Tue Aug 14, 2007 10:26 am

The Llama Book is a good introduction. I have a copy around somewhere, will have a look.[/url]

swithun
Posts: 2683
Joined: Wed Mar 29, 2006 12:24 pm

Post by swithun » Tue Aug 14, 2007 10:43 am

The first line of the Perl script should be the shebang line. It specifies the location of the Perl interpreter. On my machine, Perl is in /usr/bin. You can find out where yours is with the command
[swithun@abednego ~]$ which perl
/usr/bin/perl
So, the line is

Code: Select all

#!/usr/bin/perl
If your Perl is in one place, and the shebang line says something different, that could be why you are getting the error.

Or, the Perl interpreter is found, but your script isn't. I don't know how OS X splits the Mac side from the Unix side. Try commands like ls and pwd to work out where in the system you are from the terminal and move your Perl scripts to that location. Or, see what text editors you have access to from the terminal and do it all from there.

This page might help with your Active Perl installation, if the default one isn't working for you.

Don't give up.

User avatar
thehemulen
Posts: 428
Joined: Fri Aug 27, 2004 3:26 pm
Location: cyberspace. Berlin
Contact:

Post by thehemulen » Tue Aug 14, 2007 11:38 am

thanks for the tips fellas. yeah, i have to figure out the paths.
terminal is not my/a perl interpreter?
i wont give up. martin, you still comin' to berlin for the ccc meet? get in touch if youre over here...!
"If something is boring after two minutes, try it for four. If still boring, then eight. Then sixteen. Then thirty-two. Eventually one discovers that it is not boring at all." --John Cage.

User avatar
Martin
Posts: 1084
Joined: Mon Sep 11, 2006 1:35 pm

Post by Martin » Tue Aug 14, 2007 11:50 am

I was just over there for the CCC camp! Will be back in December for the congress.

Terminal is just a window running your shell, the program that takes commands and runs them. If you run 'perl' from there, that's your interpreter. If you have a script you want to run, saved in a file, 'perl <filename>' will make it run it. This is the easiest way. <filename> can be the name of a file in the current directory (e.g. myscript.pl), or the full path to a file anywhere on the system (e.g. /Users/thehemulen/Desktop/myscript.pl)

If you have #!/usr/bin/perl (or wherever your perl interpreter actually is on the system) at the top of your script, you can run it directly from the shell without typing 'perl', because the #! line tells the system what interpreter to run it with. To do this the script file must be marked as executable, which can be done with the command 'chmod +x <filename>'. Then to run it, you just type the filename at the shell, either with the full path or with './' to indicate the current directory, e.g. './myscript.pl'.

User avatar
thehemulen
Posts: 428
Joined: Fri Aug 27, 2004 3:26 pm
Location: cyberspace. Berlin
Contact:

Post by thehemulen » Tue Aug 14, 2007 12:00 pm

phew! all i needed was to put the .pl files in users/dirk....!!! now its hunky dory!
working my way thru this intro guide: http://www.perl.com/pub/a/2000/11/begperl2.html
do you guys actually work with perl? what for/on?
"If something is boring after two minutes, try it for four. If still boring, then eight. Then sixteen. Then thirty-two. Eventually one discovers that it is not boring at all." --John Cage.

User avatar
thehemulen
Posts: 428
Joined: Fri Aug 27, 2004 3:26 pm
Location: cyberspace. Berlin
Contact:

Post by thehemulen » Tue Aug 14, 2007 12:06 pm

great advice martin, thanks. sorry i missed you when you were just over here: definitely get in touch in dec - maybe by then i'll know enough to benefit from the congress too! : )
"If something is boring after two minutes, try it for four. If still boring, then eight. Then sixteen. Then thirty-two. Eventually one discovers that it is not boring at all." --John Cage.

swithun
Posts: 2683
Joined: Wed Mar 29, 2006 12:24 pm

Post by swithun » Wed Aug 15, 2007 4:07 pm

I don't do much with Perl these days. I used to write everything in Perl, but then I realised that it was easier to learn new languages which were better suited to different jobs than it was to try and do everything in one language.

So now I write stuff in PHP (for website stuff), Python (for rapid development of complex stuff), C (when speed of running is more important than speed of development), XSLT (for transforming data), Bash (for automating repetitive tasks) etc.. And I use Perl for quick text transforming jobs, which are too much for sed/grep.

I think learning Perl is worth it. You get to cover the basics which are common to almost all languages. But then you are able to appreciate all the good bits of other languages. PHP has useful functions because it was designed for a certain job. Python looks much nicer and is easier to read.

Post Reply