Home
11.
What happens to system variables when resetis called? For example, is @ARGV reset when reset is passed "A"?

The reset function affects all variables, including system variables. For this reason, you should be careful when you use reset

12.
Is a $#arrayvariable defined for system array variables such as @ARGV?

Yes. For example, $#ARGVcontains the largest subscript of the @ARGVarray; you can test this to determine whether your program was passed enough arguments

13.
What does the bless()function do?

The bless() function takes one or two arguments. The first argument is a reference to an object. The second argument is optional and specifies the name of a class; if the name is not specified, the default is the current class. After the call, the reference uses the name as its class name. As a result, the reference becomes an object of the class whose name was specified.

14.
What's the difference between an object and a reference?
Objects are blessed; references are not. Objects belong to a class, but references do not have to.

15.
You just added a method to some class file, but it is never called, Why?

We need to Make sure we are using the require Exporter;statement and that the name of the new function is in the @EXPORTER array.

16.
How are subroutines different from functions?

They're not; they both refer to the same conceptual things. In this lesson I simply decided to make the distinction so there would not be any confusion about calling built-in functions versus functions you define yourself.
Note that subroutines you define are, in fact, different from the built-in functions; subroutines don't control the number or type of arguments they can receive (at least, not without prototypes), and the rules of whether you can leave off the parentheses for subroutines are different. Future versions of Perl are working toward making programmer-defined subroutines and built-in subroutines closer in behavior.

17.
I want to pass two arrays into a subroutine and get two arrays out. But the two arrays get squashed into one list on the way in and on the way out. How can I keep the two arrays discrete?

The best way to do this is to use references, Another way is to modify global variables inside the subroutine, rather than passing the array data in via an argument list. Yet another way is to compress the arrays into single scalar values (using delimiters), and then expanding them back into arrays inside your subroutine.

18.
Name two reasons why subroutines are useful.

Subroutines are useful for a number of reasons:
They help break up a large script into smaller bits to help manage complexity
Procedures in subroutines can be referred to by name to make scripts more readable
Subroutines can define local variables that are more efficient, easier to manage and control than globals
If you use the same code repeatedly throughout your programs, you can put that code into a subroutine, and then just reuse it
Smaller chunks of scripts can be more easily developed and debugged

19.
Show how to call a subroutine.

Call a subroutine using one of these forms:
&thisubroutine(); # both % and parens
&thissubroutine(1,2); # with arguments
thissubroutine(1,2); # & is optional

20.
Show how to define a subroutine ?

Define a subroutine like this:
sub name {
# body of subroutine
}