running perl

I understand mac 0s X comes with perl. I'd like to start learning perl. I looked in Applications but didn't see it. Can someone please outline the steps for running perl or installing perl?"

imac G5 Mac OS X (10.4.6)

imac G5, Mac OS X (10.4.6)

Posted on May 17, 2006 5:15 PM

Reply
10 replies

May 20, 2006 1:11 PM in response to Daniel Macks

Thank you. OK I got a command line and typed perl -v and perl looks to be running.
Where do I save Perl scripts or what lines do my scripts need?

wrote my first script:

#!/usr/bin/perl
print("Hello world\n");

saved it as hello.pl in a documents folder

typed at the command line:
perl name.pl

the message is:
Can't open perl script "hello.pl": No such file or directory

Thanks

imac G5 Mac OS X (10.4.6)

May 20, 2006 6:08 PM in response to goforit

>I typed perl hello.pl at the command prompt.

This will tell perl to run the script hello.pl in the current directory. If you're not in the same directory as the hello.pl file it won't run.

In that case there are two solutions - either change to the directory where the hello.pl file is (e.g. cd ~/Documents/ if it's in your Documents folder), or tell perl where to find the script (e.g. perl ~/Documents/hello.pl)

May 21, 2006 3:52 AM in response to Camelot

Ok I've learned how to find Terminal and how to direct Perl to the appropriate folder to run a script. Any ideas about what's wrong with my first script listed in the previous message? I get this message from Perl:

Backslash found where operator expected at hello.pl line 1, near "rtf1\"
Backslash found where operator expected at hello.pl line 1, near "mac\"
Backslash found where operator expected at hello.pl line 1, near "ansicpg10000\"
Backslash found where operator expected at hello.pl line 1, near "cocoartf824\"
Backslash found where operator expected at hello.pl line 2, near "fonttbl\"
Backslash found where operator expected at hello.pl line 2, near "f0\"
Backslash found where operator expected at hello.pl line 2, near "fswiss\"
Backslash found where operator expected at hello.pl line 3, near "red255\"
Backslash found where operator expected at hello.pl line 3, near "green255\"
Backslash found where operator expected at hello.pl line 4, near "margl1440\"
Backslash found where operator expected at hello.pl line 4, near "margr1440\"
Backslash found where operator expected at hello.pl line 4, near "vieww12820\"
Backslash found where operator expected at hello.pl line 4, near "viewh11120\"
Backslash found where operator expected at hello.pl line 5, near "viewkind0
\"
(Missing semicolon on previous line?)
Backslash found where operator expected at hello.pl line 5, near "pard\"
Backslash found where operator expected at hello.pl line 5, near "tx720\"
Backslash found where operator expected at hello.pl line 5, near "tx1440\"
Backslash found where operator expected at hello.pl line 5, near "tx2160\"
Backslash found where operator expected at hello.pl line 5, near "tx2880\"
Backslash found where operator expected at hello.pl line 5, near "tx3600\"
Backslash found where operator expected at hello.pl line 5, near "tx4320\"
Backslash found where operator expected at hello.pl line 5, near "tx5040\"
Backslash found where operator expected at hello.pl line 5, near "tx5760\"
Backslash found where operator expected at hello.pl line 5, near "tx6480\"
Backslash found where operator expected at hello.pl line 5, near "tx7200\"
Backslash found where operator expected at hello.pl line 5, near "tx7920\"
Backslash found where operator expected at hello.pl line 5, near "tx8640\"
Backslash found where operator expected at hello.pl line 5, near "ql\"
Backslash found where operator expected at hello.pl line 5, near "qnatural\"
Backslash found where operator expected at hello.pl line 7, near "pardirnatural

\"
(Missing semicolon on previous line?)
Backslash found where operator expected at hello.pl line 7, near "f0\"
Backslash found where operator expected at hello.pl line 7, near "fs36 \"
(Do you need to predeclare fs36?)
Backslash found where operator expected at hello.pl line 7, near "cf0 \"
(Do you need to predeclare cf0?)
Backslash found where operator expected at hello.pl line 7, near "shad\"
Backslash found where operator expected at hello.pl line 7, near "shadx31\"
Backslash found where operator expected at hello.pl line 7, near "32\"
(Missing operator before \?)
Backslash found where operator expected at hello.pl line 7, near "shadr0\"
Backslash found where operator expected at hello.pl line 7, near "shado85 \"
(Do you need to predeclare shado85?)
syntax error at hello.pl line 1, near "rtf1\"
syntax error at hello.pl line 3, near "red255\"
syntax error at hello.pl line 4, near "margl1440\"
Execution of hello.pl aborted due to compilation errors.

May 21, 2006 7:54 AM in response to goforit

whoa. that looks scary.

If you have used textedit, make sure that you choose format>"make plain text" to ensure the file is not saved as rtf. this should solve the problem.

i have tested your script and it works fine.

If you still have problems open terminal and type in the following three lines:
cat>test.pl
#!/usr/bin/perl
print("Hello world\n");

At this point type control-z on the keyboard.

now type perl test.pl

This should work.

Powermac G4 Mac OS X (10.4.6)

May 21, 2006 4:17 PM in response to goforit

Any ideas about what's wrong with my first
script listed in the previous message?


As jzephyr psoted, that's because TextEdit saved the file as a rich text file. If you really want to learn Perl, I'd suggest getting a real text editor. If you're looking for a low-cost solution, you can't go wrong with BareBones' TextWrangler. It's plain text, it does syntax coloring (very handy!), and the price is right: free. There are probably others, too, but that's the one that springs to mind first.

charlie

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

running perl

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.