Example 1: A typical Perl command line args example. Leading garbage + will be discarded until the first line that starts with #! Perl has a wide range of command-line options or switches that you can use. In this article we'll look at some of the most useful of these. Perl uses a special array @ARGV that stores the list of command-line arguments provided to the program at execution. Simple Clients. Here is a beautiful Perl code example that process command line arguments with specified options. ... Also, if you want to have command line options such as (-a foo), you can use the getopts perl module. To enable parsing the command-line arguments, the Perl interpreter should be invoked with –s option. Assuming you start Perl as follows: perl -s script.pl -foo -bar myfile.dat. Simple clients are programs that perform actions for users in real time, usually with a finite list of URLs to act upon. We need two command line arguments as user's first and last name. There is also one important flag -n which is not mentioned in the list.-n works the same as -p, only it does not print $_ by default. This can be very useful in filtering text files. -x -x directory tells Perl that the program is embedded in a larger chunk + of unrelated ASCII text, such as in a mail message. H ow do I read or display command-line arguments with Perl? A thorough knowledge of the command line switches will enable you to create short one-time programs to perform odd little tasks. Let's see a simple example to print command line arguments. Switches in this variable are treated as if they were on every Perl command line. Perl Command Line Argument Example. 17 - Command-line Options. The core of any perl one-liner is the -e switch, which lets you pass a snippet of code on the command-line: perl -e 'print "hi\n"' prints "hi" to the console. Here’s an example: ... Here’s an example of the command line for the previous code: example.pl -a -b … In this example, we will print a welcome message with the users name as the argument from the command line. In this way Perl can replace grep | sed in a single one-liner.. For example: perl -ne 'print "$1\n" if /Messages read: (\d+)/'