Perl Script : Arrays and scalars

Arrays and scalars
Perl's built-in types, arrays and scalars. Array vari-ables begin with @ and scalar variables begin with $. In many cases, expressions
that yield arrays begin with @ and expressions that yield scalars begin with $.

But not always. Remember:
The way an expression is evaluated depends on context!

In an assignment statement, the left side determines the context. If the left side is a scalar, the right side is evaluated in scalar context. If the left side is an array, the right side is evaluated in list context.

If an array is evaluated in scalar context, it yields the number of elements in the array. The following program

my $word = @params;
print "$word\n";
prints the number of parameters. I will leave it up to you to see what happens
if you evaluate a scalar in a list context.

No comments:

Post a Comment