in reply to I come in peace for I seek your wisdom dear monks :)

$ perl helloworld.pl and the book shows that it's supposed to show up on the screen as Hello World! Thats really where I run into my problem. You see, every time I try to run it, it tells me it cannot be ran, because no such files or directory exist.

On a Unix system, in order to execute a Perl script, it has to have what is called "execute" permission. Each file has "read, write, execute" permission levels for each of "user, group, other". "man" (short for manual) is a command that you will become very familiar with! Type "man chmod" at the command prompt.

chmod 755 helloworld.pl is a common thing to do and this results in (-rwxr-xr-x), meaning that you as a user have rwx (read,write,execute permissions) to this file, the group that you belong to has r-x (read and execute, but not write)and all others have have the same permission (r-x) as your group. The first dash - at the beginning has special meaning that is not important now.

At the command prompt, type "ls -al". This should show the files and directories and this rwxrwxrwx notation, each rwx "set" is 3 bits in octal and is for user,group, other. 755 in octal is 111 101 101, the "write" bit is turned off for the group and for others, but is turned on for "user", meaning you. This scenario is common.

Now that you have the helloworld.pl program marked as exectuable (chmod 755 helloworld.pl). A Unix system looks into the file in order to decide what to do. That is why the first line in that file should be:
#!/usr/bin/perl
This is called the "shebang" line. The # means that this is a comment..sort of..except when its not..and this is one of those cases. This looks like a comment, but it is way more than a comment. As the first line, this means: run the Perl interpreter on the rest of this file.

Once you have given execute permission to the file, you can just type "helloword.pl" and it will run. Typing "perl helloworld.pl" explicitly starts the Perl interpreter and sends it the helloworld.pl file. Oh, also be aware that Unix is case sensitive. Helloworld.pl is different than helloworld.pl

Get helloworld.pl working in your default login directory before trying to move it or get it to run in a sub-directory.

  • Comment on Re: I come in peace for I seek your wisdom dear monks :)

Replies are listed 'Best First'.
Re^2: I come in peace for I seek your wisdom dear monks :)
by JavaFan (Canon) on Dec 08, 2010 at 10:59 UTC
    On a Unix system, in order to execute a Perl script, it has to have what is called "execute" permission.
    No.

    It may, or may not, be needed. It's certainly not needed in the way the book told the OP how to execute the script: perl helloworld.pl. Not also that if you try to execute a program for which you need execute permission, the shell will not complain about a missing file or directory name, but tell it will either tell you "command not found" (if a $PATH search failed to find it - this only looks for programs with execute permission), or "permission denied" (if you try execute a program by using an absolute or relative path).

      What I said is true and I think that I covered your case with:
      Once you have given execute permission to the file, you can just type "helloword.pl" and it will run. Typing "perl helloworld.pl" explicitly starts the Perl interpreter and sends it the helloworld.pl file.
      In the above, yes, "perl helloworld.pl", helloworld.pl does not need execute permission because helloworld.pl is an input file to the command "perl". Normally one would give the .pl file execute permissions and omit the need to type "perl" explictly. Note: On Unix the "file extension" of .pl doesn't matter. On Windows, there are a couple of non-obvious steps required to get a .pl file to execute in all situations without having to type "perl" first. But that is not the question here.

      If the OP cannot execute the .pl file, either the OP is in the wrong directory or has the wrong permissions or has the wrong shebang line or the path does not have the perl command.

      My advice of:

      Get helloworld.pl working in your default login directory before trying to move it or get it to run in a sub-directory.
      still appears solid to me.
        What I said is true and I think that I covered your case with:
        Once you have given execute permission to the file, you can just type "helloword.pl" and it will run. Typing "perl helloworld.pl" explicitly starts the Perl interpreter and sends it the helloworld.pl file.
        You said it was required to set execute permission. It isn't. Now the phrasing of the lines above is such that for someone unfamiliar with permission bits, it still looks like "perl helloworld.pl" requires execute permission.

        Also note that you can just type "helloword.pl" and it will run only works if either . (a dot) or the path of your current directory is in your $PATH. Given the example case from the book, the latter is very unlikely - and putting . in your path is usually strongly adviced against.

Re^2: I come in peace for I seek your wisdom dear monks :)
by Argel (Prior) on Dec 08, 2010 at 19:20 UTC
    Marshall, while the advice is appreciated, the OP is confused enough already. There is no need to add to that by mentioning different ways to run Perl scripts, especially when it brings in several confusing topics like permissions and the shebang.

    Elda Taluta; Sarks Sark; Ark Arks

      Yes, there is definitely an "information quanta" that can be conveyed in a single post and I did exceed that. It happens sometimes. Your point is well taken.