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

Note: no differentiation in declaring string or numeric variable.

Declaration of Arrays    

Syntax : @arr_name
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

Accessing Hashes:

Single element at ‘key’ position –  $hash_name(key)
All elements at once – %hash_name

 

If You need more visit our site – www.iguddy.com

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s