Set - 2

Question 11 :

How do you find the length of an array? 

Answer :



Question 12 :

What value is returned by a lone `return;' statement?

Answer :

The undefined value in scalar context, and the empty list value () in list context.
This way functions that wish to return failure can just use a simple return without worrying about the context in which they were called.

Question 13 :

What's the difference between /^Foo/s and /^Foo/?

Answer :

The second would match Foo other than at the start of the record if $* were set.
The deprecated $* flag does double duty, filling the roles of both /s and /m. By using /s, you suppress any settings of that spooky variable, and force your carets and dollars to match only at the ends of the string and not at ends of line as well -- just as they would if $* weren't set at all.

Question 14 :

Does Perl have reference type?

Answer :

Yes. Perl can make a scalar or hash type reference by using backslash operator.
For example

$str = "here we go"; # a scalar variable 
$strref = \$str; # a reference to a scalar 
@array = (1..10); # an array 
$arrayref = \@array; # a reference to an array 

Note that the reference itself is a scalar.

Question 15 :

How to dereference a reference?

Answer :

There are a number of ways to dereference a reference.
Using two dollar signs to dereference a scalar.
$original = $$strref;
Using @ sign to dereference an array.
@list = @$arrayref;
Similar for hashes.