Tuesday, May 10, 2011

What $variable and @variable means in perl

$variable signifies that the variable is a scalar variable which means that it can be assigned to a String or Number and the data type is interchangeable which means.

$foo = "Hello World";
print $foo;
$foo = 12;
print $foo;

------------------------------------------------------------------------------------------------------------

@variable signifies that the variable is an array of scalar variable.

Example :-

@bar = ("one", 2, "three");

The index starts from ZERO.

Following expression access the 1st index element.

$first = $bar[1];


Note:- @ is changed to $ as scalar variable is accessed.

No comments:

Post a Comment