Apr 9, 2014, 2:53 PM
Post #6 of 6
Oops, I actually knew that your code was more an example than a complete solution, but I did not think about it when I posted my previous message. What I really wanted to do was really just to describe one of the standard ways (perhaps the most standard way) to run Perl code from a shell (Bash or other) script.
Re: [BillKSmith] Substitute paragraph
[In reply to]
One other standard way is to have the script file start with the appropriate "shebang line" (e.g. "#!/usr/bin/perl") and to set the file permissions to execute (say, for example, "chmod 755 filename"). In this case, there is no need to use the "perl" keyword in the bash script. The Bash script line calling the script can just be:
Finally, it is also possible to inline Perl code in a Bash (or any other shell) script with something like this:
but this is acceptable, IMHO, only for very short scripts (let's say less than 10 lines or perhaps even less than 5 lines, depending on the conditions and the programmer's experience), but this should probably not be used by beginners, because it makes debugging significantly more difficult; nobody (or at least no sane person) wants to make the life of beginners more difficult, we all know that starting with a new language is far from being an easy task, there is no reason to make it more difficult.
perl -e '
<Perl code here>