![]() ![]() Many shortcuts are available to reduce the amount of typing needed. O module section shows the code Perl runs with these options.Īs seen before, the -e option accepts code as command line argument. ![]() The -n or -p option will enable this feature for perl. $ printf 'gate\napple\nwhat\nkite\n' | perl -ne 'print if !/e/'īy default, grep, sed and awk will automatically loop over input content line by line (with \n as the line distinguishing character). $ # same as: grep -v 'e' and sed -n '/e/!p' and awk '!/e/' $ printf 'gate\napple\nwhat\nkite\n' | perl -ne 'print if /at/' $ # same as: grep 'at' and sed -n '/at/p' and awk '/at/' And similar to many command line utilities, perl can accept input from both stdin and file arguments. Perl one-liners can be used for filtering lines matched by a regexp, similar to grep, sed and awk. $ # or, use -E and 'say' instead of -l and 'print' $ # -l option will be covered in detail later, appends \n to 'print' here ![]() $ # multiple statements can be issued separated by See perldoc: feature for details about the features enabled by the -E option. $ echo 'print "Hello Perl\n"' > įor short programs, you can also directly pass the code as an argument to the -e or -E options. If you want to execute a perl program file, one way is to pass the filename as argument to the perl command. Some more options will be covered in later chapters, but not all of them are discussed in this book. This chapter will show examples with -e, -l, -n, -p and -a options. perl -MRegexp::Common=net -nE 'say $
0 Comments
Leave a Reply. |