PDA

View Full Version : how to use perl




Corrosive vinyl
Jul 2, 2007, 01:02 PM
Sorry for the total newb questions, but gotta start somewhere. I got this cool book called Programming perl and have started weeding through the 1,000 some pages of it. Where can I write and compile this stuff I am learning? Do I need to get Xcode? Also, How can I open apps so I can see the code? I basically am interested in this language and want to implement it.



robbieduncan
Jul 2, 2007, 01:25 PM
Perl is not a compiled language (in the traditional sense). Just save plain text files (you can do that with Text Edit) and run them in the Terminal via perl <filename>

Corrosive vinyl
Jul 2, 2007, 02:07 PM
coolness... so just go to text edit and write out perl stuff like print "howdy, there!"\n then go to terminal and type perl <texteditfile> that is very doable, thanks!

robbieduncan
Jul 2, 2007, 02:11 PM
Just make sure TextEdit is in plain text mode. If you have the formatting toolbar find the Format->Make Plain Text command.

If you want to be able to just type perl <file> make sure you save the file in your home directory (not Documents).

You can use the cd command to change directories in Terminal to get to wherever you save it.

iSee
Jul 2, 2007, 03:06 PM
You might also look at getting a text editor that does syntax highlighting for Perl. There are free ones around.

I don't want to start another "which text editor is better" battle, but I know TextWrangler is a freeware editor with basic Perl syntax highlighting. I found the highlighting very useful as I learned the language.

cube
Jul 2, 2007, 03:13 PM
You don't need to type perl on the command line all the time

Just make the first line of the file be:
#!/usr/bin/perl

If the file is called "myscript" then you do:
chmod u+x myscript

And just run as:
myscript

robbieduncan
Jul 2, 2007, 04:02 PM
And just run as:
myscript

Probably actually as ./myscript unless the OP has added ./ (or the current directory explicitly) to the PATH.

cube
Jul 2, 2007, 04:05 PM
You don't add "./", you just add "."

robbieduncan
Jul 2, 2007, 04:12 PM
You don't add "./", you just add "."

I think you'll find I'm correct and you are wrong. I'm a professional Unix developer.


jay:~ robbie$ chmod u+x test
jay:~ robbie$ .test
-bash: .test: command not found
jay:~ robbie$ ./test
test


Note that with ./ it works and just . it gives the expected command not found?

cube
Jul 2, 2007, 04:13 PM
I'm talking about PATH

robbieduncan
Jul 2, 2007, 04:16 PM
I'm talking about PATH

In which case either will work, but as I clearly typed the whole command it was clear that I was using ./<command> to explicitly run a command in the CWD, and this was not talking about the PATH, that was a separate aside.

cube
Jul 2, 2007, 04:22 PM
You said:

unless the OP has added ./ (or the current directory explicitly) to the PATH.

I don't say it won't work. I mean real Unixers just use "."

Corrosive vinyl
Jul 2, 2007, 05:12 PM
so if i put scripts in documents/myscripts folder i just cd documents/myscripts then do perl "<file>" whatever file that may be and it runs whatever I wrote...