Perl has three built in variable types
Scalar : A scalar represents a single value.
Array : An array represents a list of values.
Hash : A hash represents a set of key/value pairs.Hash are type of arrays with the exception that hash index could be a number or string.
PERL treats same variable differently based on Context. For example
my @animals = ("camel", "llama", "owl");
Here @animals is an array, but when it is used in scalar context then it returns number of elements contained in it as following
if (@animals < 5) { ... } # Here @animals will return 3
Another examples:
my $number = 30;
Here $number is an scalar and contained number in it but when it is called along with a string then oit becomes string in stead of number
$result = "This is " + "$number";
print "$result";
Here output will be This is 30
Variable names are case sensitive; $foo, $FOO, and $fOo are all separate variables as far as Perl is concerned.
1) My : my creates lexically scoped variables instead. The variables are scoped to the block. The my operator declares the listed variables to be lexically confined to the following but not limited to
Enclosing blocks,
Conditional (if/unless/elsif/else)
Loop (for/foreach/while/until/continue)
Subroutine
eval or do/require/use'd file
2) Temporary Values via local() : A local modifies its listed variables to be "local" to the enclosing block, eval, or do FILE --and to any subroutine called from within that block. A local just gives temporary values to global (meaning package) variables. It does not create a local variable. This is known as dynamic scoping. Lexical scoping is done with my, which works more like C's auto declarations.
Because local is a run-time operator, it gets executed each time through a loop. Consequently, it's more efficient to localize your variables outside the loop. If you localize a special variable, you'll be giving a new value to it, but its magic won't go away. That means that all side-effects related to this magic still work with the localized value. This feature allows code like this to work :
# Read the whole contents of FILE in $slurp
{ local $/ = undef; $slurp = ; }
To know more kindly visit.