Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

begin w/ Perl OSX

by Anonymous Monk
on Nov 17, 2002 at 15:56 UTC ( [id://213563]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Brothers,

0 I did create an account but I can't my email this days, so I'm anonymous....
1 thx for your answers on Perl and OS X
2 Where is the best place here to post my messages about Perl and OS X for the newby ?
4 What editor to use ? I can't save my files as .pl in textedit
3 I begun to learn and type some lines, following the tutorials, and I found that I have to twist a little bit the examples if you want them to work on OS X.
that is :
example in Tutorial:Basics
[Ordinateur-de-me-XoX:~] exox% #!/usr/bin/perl /usr/bin/perl: Event not found. print "Hello World!\n"; [Ordinateur-de-me-XoX:~] exox% print "Hello World!\n"; print: Command not found. [Ordinateur-de-me-XoX:~] exox% [Ordinateur-de-me-XoX:~] exox% [Ordinateur-de-me-XoX:~] exox%
(this the terminal prompt and [Ordinateur-de-me-XoX:~] exox% is always on the screen)

So it doesn't work...
But
(example by Louis Wu) ;
[Ordinateur-de-me-XoX:~] exox% perl -e 'print "Hello World!\n";' Hello World! [Ordinateur-de-me-XoX:~] exox%
it works.

But
(example buy Defyance)
[Ordinateur-de-me-XoX:~] exox% $ man perl[Ordinateur-de-me-XoX:~] exox% $ man perl $: Command not found.
doesn't...

well, i'm lost !!

Could you tell me where or what is the problem ?? Does OS X needs a special typing or ...??

Amen,

Bro. Xav

Replies are listed 'Best First'.
Re: begin w/ Perl OSX
by larsen (Parson) on Nov 17, 2002 at 16:23 UTC
    BBEdit is a good choice if you're looking for an editor for MacOSX.

    For what concerns your other doubts, I think perlintro is a good starting point. The examples you'll find there are meant to be written in a file, then run from the command line. For example, once you saved in a file called example.pl a program like this:
    print "Hello world!\n";
    you will run it from the command line with something like this (I'm faking your own situation to be more clear):
    [Ordinateur-de-me-XoX:~] exox% perl example.pl Hello world! [Ordinateur-de-me-XoX:~] exox%
    And so on, they're all variations on the same theme.
    Another note...
    [Ordinateur-de-me-XoX:~] exox% print "Hello World!\n"; print: Command not found. [Ordinateur-de-me-XoX:~] exox%
    This does not work 'cause you're speaking Perl to to someone who does not understand Perl, the shell. Through the shell you can only "call" someone who can understand the Perl language, that is the Perl interpreter. It is precisely what you're doing when you type from the command line:
    [Ordinateur-de-me-XoX:~] exox% perl example.pl
Re: begin w/ Perl OSX
by graff (Chancellor) on Nov 18, 2002 at 04:31 UTC
    It seems that you're having as much trouble understanding the unix command line (the "brand new feature" for macs, introduced in OS X, which everyone else has been using for decades), as you are getting started with perl scripting.

    It appears that your system uses the string "exox%" as the "command-line prompt" -- the final "%" is often a clue about what sort of "shell" is running to process your commands. Are you able to look up a "Help" page somewhere on your system that explains what the "shell" is, and how to use it? If so, it's likely to be a long explanation, and you should take the time to read it, even if it seems cryptic at first glance. Many linux and other unix users use the "bash" shell, which usually presents a prompt with a final "$" instead of a final "%" -- that's why Defyance suggested something that looked like "$ man perl" -- he included the command-prompt character, assuming you would understand it as such. (And when you type the entire string "$ man perl" as a command, your system thinks that "$" was supposed to be the name of an executable command, and naturally reported "$: Command not found", because there is no command called "$".

    The command-line interface for OS X is basically just like any other unix command line interface. But, coming from the traditional GUI-only mac orientation, it may all seem too foreign and inexplicable at first. Remember this one thing about the command line, and you'll get a handle on it:

    prompt-string% name_of_program -options arguments
    The "prompt-string%" is the part that the shell prints to let you know it's waiting for your input; the first word you type is supposed to be the name of a command (ie. the name of a file that contains an executable program), like "ls", "man", "cp", "perl", "perldoc", or the name of a perl script file that you have created and made executable by putting
    #!/usr/bin/perl
    as the first line of your perl script file and running the command
    chmod +x your_perl_script_file_name
    to tell OS X that this should be treated as an eXecutable file.

    "-options" are things that may or may not be needed to make a given command do what you want, and this depends on the command that you're running -- each command should have a "man page" (short for "manual page") viewable by typing man command_name as a command, e.g.

    man cp
    This will explain what the command does (the "cp" command in this example), as well as what options are available, and how they affect what the command does.

    "arguments" are typically names of files that the command is supposed to operate on (read, write, etc), or they can be strings that pertain to particular options -- eg:

    man man man -k directory
    The first command "man man" says: print the man page for the "man" command. On that page, you'll see that the "-k" option can be used to list all commands that pertain to a given keyword. The second command above "man -k directory" demonstrates the use of the "-k" option -- it will list all commands that have anything to do with operating on directories.

    Again, the syntax and possibilities for arguments will depend on the particular command, and the man page for each command will explain this.

    As you write perl scripts that you want to execute from the command line, you will be able to design the script so that it can also accept options and arguments. These will be available to the script in the array @ARGV. Of course, the perl programs you write will not have man pages explaining their command-line usage, unless you write them yourself; luckily, perl's "plain old documentation" (pod) facility makes that pretty simple (try "man -k pod"). Have fun.

Re: begin w/ Perl OSX
by em (Scribe) on Nov 17, 2002 at 17:21 UTC
    In addition to BBEdit (which available in a pay version and a time-limited 'demo' version), Mac OS X also comes with Emacs and vi.

    Both Emacs and vi run in Terminal. They are completely text based and don't have a graphical interface (well, they can, but we're not gonna talk about installing X and Fink). There are GUI based editors that are free (like JEdit).

    You can read an Emacs tutorial here.

    Vi tutorial available here.

    You'll need to enter the examples in a text editor and then save it (perhaps as 'hello.pl'.

    After saving the example, you run it by typing 'perl hello.pl'.

    Welcome to Perl! Perlmonks is here to help, but please read documentation before asking a question. If you don't like reading docs in a Terminal, try perldoc.com.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://213563]
Approved by ybiC
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-03-29 07:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found