PERL Data Types and Objects
PERL Data Types and Objects
Perl has three data types:
- scalars – Scalars can hold elementary data, i.e., string, integer, float …
- arrays of scalars – Arrays of scalars in short arrays can hold arrays of scalar values.
- associative arrays of scalars. – Associative arrays of scalars are also called as hashes contain key, value pairs. There are like arrays only but the difference is these are indexed by strings where arrays are indexed by integers.
Declaration of scalar
Syntax : $var_name
Example: $name # holds string value
$num #holds numeric value
Example: $name # holds string value
$num #holds numeric value
Note: no differentiation in declaring string or numeric variable.
Declaration of Arrays
Syntax : @arr_name
Example: @name #holds a list of scalar values
Example: @name #holds a list of scalar values
Declaration of Hashes
Syntax : %hash_name
Accessing Scalar:
$var_name
Accessing Arrays:
Single element at index ‘i’ – $arr_name[i]
All elements at once - @arr_name
All elements at once - @arr_name
Accessing Hashes:
Single element at ‘key’ position - $hash_name(key)
All elements at once – %hash_name
All elements at once – %hash_name
Comments
Post a Comment