Perl help/101

ByerlyRips

Registered
Just for some very basic knowledge, I wanted to learn a little bit about perl in OS X. I just want to get my toes a little bit wet and I was wondering how to run some basic commands and/or scripts.

When I type this in the terminal...
Code:
#!/usr/bin/perl

All I get is - "tcsh: /usr/bin/perl: Event not found."


What am I missing?
 
Hi -

#! is a special syntax at the top of a script which basically means "run every line which follows this one through the specified interpreter". So the code you provided should be in a text file rather than entered on the command line. Of course you need more in your text file or you're basically saying "run the following interpreter but don't give it any commands". So for example try this:

Code:
#!/usr/bin/perl
print "Hello from your first perl script\n";
Save this in a file in your home directory, call it test1.pl for example. Then you need to make the file executable (i.e. when you type its name it will run) with the following command in the terminal:
Code:
chmod +x ./test1.pl
Finally, run your new program with:
Code:
./test1.pl

Hope that helps!
 
Ahh, I see! So perl is more about saving scripts and executing them from the command line rather than typing them in the terminal? Is there a good place you can point me to for "perl for dummies"? Thanks for your help.
 
Exactly right. Although it can be used on the command-line with the "-e" flag it's much more convenient to save your programs in a script and then execute them.

In a terminal do "man perlintro" for an introduction, although it's easier to read on the web at http://perldoc.perl.org/perlintro.html. Check out the tutorials on the same site at http://perldoc.perl.org/index-tutorials.html. There's a wealth of information on that site alone, and you can find plenty of others on Google, such as http://www.webdesigns1.com/perl/tutorial.html and http://www.perl.com/pub/a/2000/10/begperl1.html.

Have fun!
 
Back
Top