Logo F2FInterview

Perl Interview Questions

Q   |   QA

In Perl, command line arguments are stored in an array @ARGV. Hence $ARGV[0] gives the first argument $ARGV[1] gives the second argument and so on. $#ARGV is the subscript of the last element of the @ARGV array, so the number of arguments on the command line is $#ARGV + 1.

Step 1: Get the size of the array using the scalar context on the array. Eg. @array = (1,2,3);
print ; "Size: ",scalar @array,"\n";
Step 2: Iterate through the array using a for loop and print each item.

a.)Grooving and shortening of arrays.
Grooving and shortening of arrays can be done by directly giving a non existent index to which Perl automatically adjusts the array size as needed.

b.)Splicing of arrays
Splicing copies and removes or replaces elements from the array using the position specified in the splice function instead of just extracting into another array.

a.) Goto label

In the case of goto LABEL, execution stops at the current point and resumes at the point of the label specified. It cannot be used to jump to a point inside a subroutine or loop.

b.) Goto name

The goto &NAME statement is more complex. It allows you to replace the currently executing subroutine with a call to the specified subroutine instead.
This allows you to automatically call a different subroutine based on the current environment and is used to dynamically select alternative routines.

c.) Goto expr

Goto expr is just an extended form of goto LABEL. Perl expects the expression to evaluate dynamically at execution time to a label by name

When Eval is called with EXPR, the contents of the expression will be parsed and interpreted every time the Eval function is called.

With Eval BLOCK, the contents are parsed and compiled along with the rest of
the script, but the actual execution only takes place when the eval statement is reached. Because the code is parsed at the time of compilation of the rest of the script, the BLOCK form cannot be used to check for syntax errors in a piece of dynamically generated code.

In order to link this F2FInterview's page as Reference on your website or Blog, click on below text area and pres (CTRL-C) to copy the code in clipboard or right click then copy the following lines after that paste into your website or Blog.

Get Reference Link To This Page: (copy below code by (CTRL-C) and paste into your website or Blog)
HTML Rendering of above code: