On Dec 22, 2004, at 3:53 PM, Isaac Sherman wrote:
#!/usr/bin/perl use strict; use warnings;
An excellent start! Always ask Perl for all the help it can give you.
Then, when, in the terminal, I typed: hw.pl while in the same directory, I
got the following message.
tcsh: hw.pl: Command not found.
My meanderings in the Terminal showed that /usr/bin/perl does indeed exist.
If it didn't, you'd get a different error:
-bash: ./test.pl: /usr/bin/perl: bad interpreter: No such file or directory
As you can see, I'm using bash, but the error you'd get from tcsh would be similar. The point is that the error message isn't just telling you that *something* couldn't be found, it's also telling you *what* it couldn't find - /usr/bin/perl. The message you're getting, on the other hand, is saying it can't find hw.pl - that's a different error.
I also tried chmod 755 on the file, but didn't change anything.
Of course not - if the permissions were wrong, you'd get a different error:
-bash: ./test.pl: Permission denied
That's not the error you got though, so there's no reason to think that permissions were the problem.
Okay, what's that leave then? Well, let's review what we know: hw.pl exists and has the correct perms, but the shell can't find it. Well, where's the shell looking for it? That's listed in the environment variable PATH. Show the value for PATH with the 'echo' command:
Sherm-Pendleys-Computer:~ sherm$ echo $PATH /sw/bin:/sw/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin
You'll notice that the current directory '.' is not in my PATH. That means that, if a script is in the current directory, I can't simply type its name - I'll get the "command not found" error you've seen. Instead, I have to tell the shell explicitly where to find it, by including the full path:
Sherm-Pendleys-Computer:~ sherm$ test.pl -bash: test.pl: command not found Sherm-Pendleys-Computer:~ sherm$ ./test.pl Howdy, world!
sherm--
Cocoa programming in Perl: http://camelbones.sourceforge.net Hire me! My resume: http://www.dot-app.org