PERL Variables

                                                                                

 

PERL Variables

  • Types of PERL variables are :

  • Variables do not need to be declared.
  • Variable names are case sensitive, so $Date and $date are different variables

 

String Type:

  • String types in Perl are like those in other programming language. Strings are treated literally when enclosed in quotation marks (either single or double). Escape sequences can be used with Perl strings. These are the most common:
\n newline
\t tab
\b backspace
  • Some escape sequences for strings have special meaning to Perl:
\l change next character to lower case
\u change next character to upper case
\ literal single quotation mark
\ literal double quotation mark
\\ backslash

 

Numerical Literals:

6 Integer
12.6 Floating Point
1e10 Scientific Notation
6.4E-33 Scientific Notation
4_348_348 Underscores instead of commas for long numbers
0xffff Hexadecimal
0577 Octal

qq operators:

  • Instead of single and double quotes, we can use qq operators. So,

Line1. qq(This is a test)

Line . “This is a test”

#Line 1 & Line 2 has same meaning.

Single and double quotes:

  • Double quotation marks allow expansion of variables within them. Single quotes do not.
  • For example:

“My name:$name”; is not the same as

‘My name:$name’;

    • 1st print will fetch the value of $name
    • 2nd print will treat $name as a string only;

Variable Declaration :

  • Unlike other languages there is no need to declare the variable.
  • When the variable is assigned an initial value, Perl can figure out the data type.

 

Assigning values :

  • Variables are assigned values using the equal sign.
  • Example:

$p=1;

$ = This is Sach Kumar ; $d=“Software-developer” ;

  • We can assign operation results.

$result=$var1+$var2;

 

                                                                                                                         

 

Leave a Reply

Your email address will not be published. Required fields are marked *