Ans: Perl scripting is the use of the Perl programming language for writing scripts to automate tasks, manipulate text data, and perform system administration.
Ans: Perl supports scalar, array, hash, and filehandle as the basic data types.
Ans: Variables in Perl are declared using the '$' symbol for scalars, '@' symbol for arrays, and '%' symbol for hashes.
Ans: 'my' creates a lexically scoped variable, while 'local' creates a dynamically scoped variable that retains its value until the enclosing block is exited.
Ans: You can open a file for reading using the 'open' function with the filehandle and file name, or for writing using 'open' with the '>', '>>', or '+>' mode.
Ans: Regular expressions are patterns used for matching and manipulating text. Perl has robust regular expression support, allowing powerful text processing capabilities.
Ans: Regular expression pattern matching in Perl is performed using the '=~' operator or the 'm//' operator.
Ans: 'my' declares a variable with a limited scope within the enclosing block, while 'our' declares a variable that is accessible across packages.
Ans: The 'split' function is used to split a string into an array based on a specified delimiter.
Ans: In Perl, the 'scalar' function can be used to find the length of an array, returning the number of elements.
Ans: Strings can be concatenated using the '.' operator or by simply placing them next to each other.
Ans: The 'chomp' function is used to remove the trailing newline character from a string read from input.
Ans: Command-line arguments can be accessed using the special array '@ARGV' in Perl.
Ans: References in Perl allow you to create and manipulate complex data structures like arrays and hashes, enabling dynamic memory allocation.
Ans: The 'sort' function in Perl can be used to sort an array in ascending or descending order.
Ans: The 's///' operator or the 'substitute' function is used to replace a substring with another in a string.
Ans: 'use strict' enforces the use of strict variable declaration and scoping, helping to catch errors and enforce good programming practices.
Ans: Reading from a file is typically done using a filehandle and the 'readline' operator '<>' or the 'getline' function.
Ans: Perl modules are reusable packages of code that provide additional functionality. They can be imported using the 'use' or 'require' statement.
Ans: Errors or exceptions in Perl can be handled using the 'eval' function and the 'die' function to generate error messages.
Ans: This can be accomplished by using the 'File::Find' module along with regular expressions or the 'File::Find::Rule' module.
Ans: 'split' is used to divide a string into an array based on a specified delimiter, while 'join' combines elements of an array into a string using a specified separator.
Ans: System commands can be executed in Perl using backticks (command
) or the 'system' function.
Ans: The diamond operator reads input either from standard input or from files specified as command-line arguments, allowing for versatile input handling.
Ans: Perl scripts can be debugged using tools like 'perl -d', 'perl -w', 'Data::Dumper' for variable inspection, or by incorporating 'warn' and 'print' statements for troubleshooting.