in reply to Using Perl on OS X

Your second try worked. The dollar sign in those instructions represents the command line prompt. Most *nix commands are silent on success. You can now run the script by typing ./my_program at the prompt.

Even without running ./my_program as an interpreter script, with executable permissions set by the chmod command, you can run it by typing perl my_program

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Using Perl on OS X
by 1st_try (Initiate) on Sep 13, 2002 at 05:53 UTC

    Thanks! I actually have a few more questions:

    When I type "chmod a+x my_program" (no $ sign) am I supposed to get some response? It didn't seem to return anything. I then typed "perl my_program" and again, no response. Am I supposed to see a "Hello, world!" line pop up? If not, can someone provide me a simple Perl code that will create a response?

    One more question: I'm supposed to start every new script with:  #!usr/bin/perl right? I've double-checked already and made sure Perl is in that directory!

    Thanks!

      When I type "chmod a+x my_program" (no $ sign) am I supposed to get some response?

      No. That chmod call sets a bit in your file's directory entry that marks it as executable by all users. That way, when you type ./my_program, the system knows it can execute your script. There's usually no response.

      If you're curious, you can type man chmod; that will explain the various bits that can be set to allow reading, writing, and executing the file for the owner, his group, or all users.

      One more question: I'm supposed to start every new script with: #!usr/bin/perl right? I've double-checked already and made sure Perl is in that directory!

      Correct! The '#!' tells the system that you're about to tell it what program to use to run the file.

      You could add a -w to that line if you want to run your program with warnings enabled. The "canonical" way to start a script is:

      #!/usr/bin/perl -w use strict;
      use strict turns on additional features like errors for undeclared variables.

      If you're using a more recent perl, you could replace the -w with "use warnings;", but I think that can wait until you get through your first perl book.

      Good luck!
      --
      Mike