·  PERL – Syntax – Variables - Reference

 

- Info:

  - Reference is scalar which holds memory address at which some data is stored, like value of another scalar.

  - To get the address at which variable is stored use prefix '\' before variable name like this \$name.

  - To get data which is stored at address to which reference points use prefix '$' before variable name like this $$name.

 

- Test.pl

  #Test variable.-----------------------------------------------------------------------------

  $name     = "John";    #Variable  $name holds value "John" at some memory address.

  $ref      = \$name;   #Reference $ref  holds address 0x182e7e8 at which "John" is stored.

  $nameCopy = $$ref;    #Value stored at reference $ref save to new variable $nameCopy at another address

 

  #Test variable.-----------------------------------------------------------------------------

  print \$name;         #SCALAR(0x182e7e8). Display address at which value of variable $name is stored.

  print  $ref ;         #SCALAR(0x182e7e8). Display address to which reference points.

  print $$ref ;         #John.          Display value stored at address $ref.

  print  $name;         #John.          Display value of varaible $name.