Yes, I dare to say so ;-) But if that doesn't work, you might also need to check:
- sufficient execution (and reading) permissions: use chmod 755 my_program.pl or at least chmod u+rx my_program.pl to tell the OS that this file is a program
- a $PATH environment variable that contains . (current directory) or the directory your script is stored, e.g. $HOME/bin or ~/bin . Some consider adding "." to the PATH environment variable a security risk. Personally, I wouldn't care too much for an individual account on a private/non-production system (the system owned by you alone). Use echo $PATH to see your current settings. Add a line like export PATH=
".:$PATH""$PATH:." at the end of your ~/.environment or ~.bashrc file (assuming you're using bash). Alternatively you can run your program like ./my_program.pl (if it is in the same directory). OR you save your program in a directory, that is already in your environments PATH variable - like ~/bin (~ is a shortcut for $HOME or /home/koolgirl/ or where your account might be located).
- /usr/bin/perl does really exist
- a file system mounted without 'noexec' attribute (usually the case)
- ... there are more, but the most likely stuff is listed above
I guess, most of these conditions are already met for your system, so all you need to do after editing your
new Perl program is to do a
chmod 755 my_program.pl once and run it as
./my_program.pl.
See the PATH-comment if you insist on
my_program.pl.
The original problem was that the missing slash prevented the system to find the perl binary which is usually located in /usr/bin/perl but not in usr/bin/perl . It might have worked when you cd to / first, but this is nonsense. Fix the first line and it can be started (potentially) anywhere.
Update: Argl, oko1 is right with the 644 - thanks - how could that happen? (s/644/755/)
In agreement with Oko1's comment the dot is put at the end of the PATH for slightly improved security. A mistyped command or a legal program name that is not within $PATH - or not installed at all - can be executed when injected into the (visited) local directory. The truely paranoid careful and responsible person will use the slightly inconvenient ./my_program.pl form (or install the program in a proper location) and never let a . enter the $PATH variable - an absolute no-no for root and other high previledged users. As said before, no good idea to do that (the dot thing) on a system accessible by other users.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.