programming-examples/perl/Datatype/Basic Perl Datatypes.pl

16 lines
929 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
#Scalars are always prefixed with $,
#arrays with an @, and
#hashes with a %.
If something is a variable, and it doesn't have a special character in front of it, it might be a filehandle.
Special Character What it Denotes Example
$ Scalar $number = 123.44; $string = 'aaaa';
@ Array @numberArray =(1,2,3);
@stringArray = ('elmt1', 'elmt2',3 );
$<var>[ ] Array Element print $stringArray[2];
$stringArray[4] = 'newstring';
% Hash %hashName = ('key' => 'value', 'key2'=>'value2');
$<var>{ } Hash Lookup print $hashName{'key'}; # prints 'value'
$hashName{'key3'} = 'value3'; # sets 'key3'