Sunday, September 13, 2026

Perl CLI Commands Quiz

Perl CLI Commands Quiz


1. Which command runs a Perl script named script.pl?

   A. perl-run script.pl

   B. execute perl script.pl

   C. perl script.pl

   D. run script.pl


2. Which option tells Perl to execute the supplied string as a program?

   A. -i

   B. -e

   C. -n

   D. -p


3. What does perl -v primarily display?

   A. All installed Perl modules

   B. The current working directory

   C. Perl version information

   D. The contents of the current script


4. Which command checks a Perl script for syntax errors without executing it normally?

   A. perl -x script.pl

   B. perl -d script.pl

   C. perl -c script.pl

   D. perl -s script.pl


5. Which command executes print "Hello\n" directly from the command line?

   A. perl -n 'print "Hello\n"'

   B. perl -i 'print "Hello\n"'

   C. perl -p 'print "Hello\n"'

   D. perl -e 'print "Hello\n"'


6. Which command enables warnings for a Perl script?

   A. perl -c script.pl

   B. perl -w script.pl

   C. perl -i script.pl

   D. perl -x script.pl


7. Which command enables Perl's debugger when running script.pl?

   A. perl -c script.pl

   B. perl -i script.pl

   C. perl -d script.pl

   D. perl -v script.pl


8. What does perl -p -e 'print' file.txt do?

   A. Compiles the file without reading it

   B. Starts the Perl debugger

   C. Deletes every line from the file

   D. Processes each input line and prints it


9. Which switch makes Perl process input with an implicit loop but does not automatically print each line?

   A. -p

   B. -i

   C. -d

   D. -n


10. Which command edits files in place using Perl's substitution one-liner?

   A. perl -pd -e 's/foo/bar/g' file.txt

   B. perl -pv -e 's/foo/bar/g' file.txt

   C. perl -pc -e 's/foo/bar/g' file.txt

   D. perl -pi -e 's/foo/bar/g' file.txt


11. Which command reads Perl code from standard input?

   A. perl -

   B. perl stdin

   C. perl --input

   D. perl -stdin


12. Which command displays Perl's command-line help?

   A. perl -help perlrun

   B. perldoc perlrun

   C. perlman perlrun

   D. perl --help-all


13. Which command runs a Perl one-liner with taint checking enabled?

   A. perl -T -e '...'

   B. perl -d -e '...'

   C. perl -w -e '...'

   D. perl -t -e '...'


14. Which command sets a Perl library search path for the current invocation?

   A. perl -Ilib script.pl

   B. perl -P lib script.pl

   C. perl -Llib script.pl

   D. perl -Mlib script.pl


15. Which command loads a Perl module before running the supplied code?

   A. perl -LModule -e '...'

   B. perl -CModule -e '...'

   C. perl -MModule -e '...'

   D. perl -IModule -e '...'


16. Which command treats Perl warnings as fatal errors?

   A. perl -c script.pl

   B. perl -v script.pl

   C. perl -Mwarnings=FATAL,all script.pl

   D. perl -w script.pl


17. Which command enables strict mode for a Perl one-liner?

   A. perl -Mstrict -e '...'

   B. perl -Istrict -e '...'

   C. perl -wstrict -e '...'

   D. perl -dstrict -e '...'


18. Which command prints the Perl installation's executable path using the shell's command lookup?

   A. which perl

   B. whereis python

   C. find perl

   D. locate perl.exe


19. Which command shows documentation for the Perl function split?

   A. perl -f split

   B. perlhelp split

   C. perldoc -m split

   D. perldoc -f split


20. Which command runs a Perl script and passes hello as its first command-line argument?

   A. perl script.pl hello

   B. perl hello script.pl

   C. perl -e script.pl hello

   D. perl -a script.pl hello

1 comment:

perlknowledge said...

Which command runs a Perl script named script.pl?

This invokes the Perl interpreter with script.pl as the program to execute.

Which option tells Perl to execute the supplied string as a program?

The -e option allows Perl code to be supplied directly on the command line.

What does `perl -v` primarily display?

The -v option displays Perl version information and related interpreter details.

Which command checks a Perl script for syntax errors without executing it normally?

The -c option checks syntax and compilation without running the program normally.

Which command executes `print "Hello\n"` directly from the command line?

The -e switch executes the supplied Perl code directly from the command line.

Which command enables warnings for a Perl script?

The -w option enables warnings for the Perl program.

Which command enables Perl's debugger when running script.pl?

The -d option starts the Perl debugger for the script.

What does `perl -p -e 'print' file.txt` do?

The -p switch creates an implicit input loop with automatic printing, while -e supplies the code.

Which switch makes Perl process input with an implicit loop but does not automatically print each line?

The -n switch wraps the supplied code in an implicit input loop without automatic printing.

Which command edits files in place using Perl's substitution one-liner?

The -i switch enables in-place editing, while -p and -e provide the processing loop and substitution.

Which command reads Perl code from standard input?

A single dash tells Perl to read the program from standard input.

Which command displays Perl's command-line help?

This displays documentation for Perl's command-line switches and execution options.

Which command runs a Perl one-liner with taint checking enabled?

The -T switch enables taint checking, and -e supplies the one-line program.

Which command sets a Perl library search path for the current invocation?

The -I option adds the specified directory to Perl's module search path for that invocation.

Which command loads a Perl module before running the supplied code?

The -M option loads the named module before executing the supplied code.

Which command treats Perl warnings as fatal errors?

The warnings pragma can be loaded with FATAL,all to make warnings fatal.

Which command enables strict mode for a Perl one-liner?

The -M option loads the strict pragma before executing the supplied code.

Which command prints the Perl installation's executable path using the shell's command lookup?

On systems providing which, this reports the Perl executable selected through the shell's command path.

Which command shows documentation for the Perl function `split`?

The -f option to perldoc requests documentation for a Perl built-in function such as split.

Which command runs a Perl script and passes `hello` as its first command-line argument?

Arguments placed after the script name are available to the Perl program through its command-line argument list.