For the following piping in a Bash script :
Bash command | perl -ne 'single line perl command' | Another Bash command
The Perl command could only be single line. How about if I want to write more complex multi-line Perl commands. Could I use multiple “-e” options for each perl command line, such as :
perl -n -e 'command line 1' -e 'command line 2' -e 'command line 3'
Or could I use a “Here Document” for the multi-line Perl codes (the perl options, such as “-n”, should still be able to be specified in such case.) ?
If “Here Document” could be used, could anyone illustrate how to use it with an example.
Thanks in advance for any suggestion.
If your Perl script is simply too long to be controllable on a single line (with semi-colons separating Perl statements), then
bashis quite happy to extend your single quoted argument across as many lines as you need:Also the ‘perldoc perlrun’ manual says:
So you could also do:
If the script gets bigger than, say, 20 lines (somewhere between 10 and 50, somewhat according to choice), then it is probably time to separate the Perl script into its own file and run that instead.