SlideShare une entreprise Scribd logo
1  sur  9
PERL NAMES,VALUES AND
VARIABLES
BY
SANA MATEEN
6/18/2016
1
NAMES IN PERL
 Perl manipulates variables which have a name.
 A value is assigned to/stored in variable by assignment statement of the
form
name=value
 Perl distinguishes between singular name and plural name.
A singular name –holds single item of data– scalar value
A plural name for variable – hold collection of data items —
an array or hash
 Starting special character of variable denotes the kind of thing that
name stands for
 $ ---- Scalar data
 @ ----- Array
 % ----- Hash
 & ----- Sub routine
6/18/2016
2
NAMES IN PERL...
 Valid characters are letters,digits,underscores.
 First character after special character can be a letter or underscore.
 Names may also have non-alphanumeric character after special character.
$$,$? (system reserved names in Perl )
 Each kind of data has separate namespace.
 Special character determine the context in which the name is being used.
 In C language a new variable is declared as
int i=1;
float data[9];
 Scope of variable depends on the part of program in which the variable is visible and
available for use.
 Global scope and local scope.
 Variable declaration in perl –
$a=5;
my $a=10;
 A variable comes into existence when declared or first used with special value denoted by
undef
undef $x;
6/18/2016
3
NAMES IN PERL...
 use strict ‘var’; (or) use strict;
 It tells perl to insist on declaration by placing the line.
 At the start of script variables are declared using
 my $x,$y;
#!/usr/bin/perl
@ages = (25, 30, 40);
@names = ("John Paul", "Lisa", "Kumar");
print "$ages[0] = $ages[0]n"; print "$ages[1] = $ages[1]n";
print "$ages[2] = $ages[2]n"; print "$names[0] = $names[0]n";
print "$names[1] = $names[1]n"; print "$names[2] = $names[2]n";
6/18/2016
4
A scalar is a single unit of data. Perl recognizes two kinds of scalar data , a String
and Numbers . There’s no difference between integers and real numbers both are
same.
Here is a simple example of using scalar variables −
#!/usr/bin/perl
$age = 25; # An integer assignment
$name = "John Paul"; # A string
$salary = 1445.50; # A floating point
print "Age = $agen";
print "Name = $namen";
print "Salary = $salaryn";
This will produce the following result −
Age = 25 Name = John Paul Salary = 1445.5
Strings are stored as sequence of bytes of unlimited length . Perl is dynamically typed
language (System keeps track of whether a variable contains a numeric value or string
value).Depending on the context strings are converted to int.
Eg:
If int/num occurs in String context, operand for string operator , perl will convert it to
string
Numeric Scalars
A scalar is most often either a number or a string. Following example demonstrates the
usage of various types of numeric scalars −
6/18/2016
5
#!/usr/bin/perl
$integer = 200;
$negative = -300;
$floating = 200.340;
$bigfloat = -1.2E-23;
# 377 octal, same as 255 decimal
$octal = 0377;
# FF hex, also 255 decimal
$hexa = 0xff;
print "integer = $integern";
print "negative = $negativen";
print "floating = $floatingn";
print "bigfloat = $bigfloatn";
print "octal = $octaln";
print "hexa = $hexan";
This will produce the following result −
integer = 200 negative = -300 floating = 200.34 bigfloat = -1.2e-23 octal = 255 hexa =
String Scalars
Following example demonstrates the usage of various types of string scalars.
Notice the difference between single quoted strings and double quoted strings −
#!/usr/bin/perl
$var = "This is string scalar!";
$quote = 'I m inside single quote - $var';
$double = "This is inside single quote - $var";
$escape = "This example of escape -tHello, World!";
print "var = $varn";
print "quote = $quoten";
print "double = $doublen";
print "escape = $escapen";
6/18/2016
6
STRING CONSTANTS/LITERALS
 String constant and literals can be enclosed in single or double quotes.
 The string is terminated by first next occurrence of quote which started it , so single
quoted strings can include double quotes and vice versa.
 Single quoted strings are treated as it is-
‘Fridayn’
 ‘Friday’--- String
 ‘Fridayn’---String with seven characters including last character which is a new
line.
 n-newline,t-tab,U-uppercase
 There is more than one way to choose your own quote
 1.quote — q
 2.double quote– qq
 q /any string/
 or q(any string) and qq(any string), qq /any string/
6/18/2016
7
VARIABLES AND ASSIGNMENT
 Perl uses – ‘=‘ as the assignment operator. It returns a value. This permits
statement like
 $b=4+($a=3);
 $a=“Burger”;
 $b=“Sandwich $a” //$b would give “Sandwich Burger”
 $c=“turkey $a”;
 Scalar variable names start with--$
 $a=“java”;
 $b=“${a} script”;//value is javascript
6/18/2016
8
<STDIN>
 <STDIN>is used for acquiring input from keyboard.If no input is queued
perl will wait until a line is typed and the return key pressed.
 End-of-file
ctrl - D  Unix
ctrl - Z  DOS
 They cause the return to be undefined, it evaluates to “ “ .
 The empty string is treated as false in boolean context.
while(<STDIN>){
.....
}
To process all statements until the end of file is reached.
While(defined <STDIN>){
...
}
6/18/2016
9

Contenu connexe

Tendances

Tendances (20)

Multiprocessor architecture
Multiprocessor architectureMultiprocessor architecture
Multiprocessor architecture
 
Attribute oriented analysis
Attribute oriented analysisAttribute oriented analysis
Attribute oriented analysis
 
Principle source of optimazation
Principle source of optimazationPrinciple source of optimazation
Principle source of optimazation
 
Semantic nets in artificial intelligence
Semantic nets in artificial intelligenceSemantic nets in artificial intelligence
Semantic nets in artificial intelligence
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Loops in flow
Loops in flowLoops in flow
Loops in flow
 
Online Shopping Agent in AI
Online Shopping Agent in AIOnline Shopping Agent in AI
Online Shopping Agent in AI
 
Java threads
Java threadsJava threads
Java threads
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Datagrams
DatagramsDatagrams
Datagrams
 
Taxonomy for bugs
Taxonomy for bugsTaxonomy for bugs
Taxonomy for bugs
 
Learning set of rules
Learning set of rulesLearning set of rules
Learning set of rules
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
Partial redundancy elimination
Partial redundancy eliminationPartial redundancy elimination
Partial redundancy elimination
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generation
 
Query processing and optimization (updated)
Query processing and optimization (updated)Query processing and optimization (updated)
Query processing and optimization (updated)
 
Mining single dimensional boolean association rules from transactional
Mining single dimensional boolean association rules from transactionalMining single dimensional boolean association rules from transactional
Mining single dimensional boolean association rules from transactional
 
Domain model Refinement
Domain model RefinementDomain model Refinement
Domain model Refinement
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Multithreading
MultithreadingMultithreading
Multithreading
 

Similaire à Perl names values and variables

Lecture 23
Lecture 23Lecture 23
Lecture 23
rhshriva
 
Crash Course in Perl – Perl tutorial for C programmers
Crash Course in Perl – Perl tutorial for C programmersCrash Course in Perl – Perl tutorial for C programmers
Crash Course in Perl – Perl tutorial for C programmers
Gil Megidish
 

Similaire à Perl names values and variables (20)

Introduction to perl_lists
Introduction to perl_listsIntroduction to perl_lists
Introduction to perl_lists
 
Scalar data types
Scalar data typesScalar data types
Scalar data types
 
Perl slid
Perl slidPerl slid
Perl slid
 
newperl5
newperl5newperl5
newperl5
 
newperl5
newperl5newperl5
newperl5
 
Complete Overview about PERL
Complete Overview about PERLComplete Overview about PERL
Complete Overview about PERL
 
Introduction to perl_control structures
Introduction to perl_control structuresIntroduction to perl_control structures
Introduction to perl_control structures
 
Lecture 23
Lecture 23Lecture 23
Lecture 23
 
Beginning Perl
Beginning PerlBeginning Perl
Beginning Perl
 
Tutorial perl programming basic eng ver
Tutorial perl programming basic eng verTutorial perl programming basic eng ver
Tutorial perl programming basic eng ver
 
Perl Scripting
Perl ScriptingPerl Scripting
Perl Scripting
 
Perl intro
Perl introPerl intro
Perl intro
 
LPW: Beginners Perl
LPW: Beginners PerlLPW: Beginners Perl
LPW: Beginners Perl
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
Crash Course in Perl – Perl tutorial for C programmers
Crash Course in Perl – Perl tutorial for C programmersCrash Course in Perl – Perl tutorial for C programmers
Crash Course in Perl – Perl tutorial for C programmers
 
You Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsYou Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager Needs
 
Perl tutorial
Perl tutorialPerl tutorial
Perl tutorial
 

Plus de sana mateen

Plus de sana mateen (20)

Files
FilesFiles
Files
 
PHP Variables and scopes
PHP Variables and scopesPHP Variables and scopes
PHP Variables and scopes
 
Php intro
Php introPhp intro
Php intro
 
Php and web forms
Php and web formsPhp and web forms
Php and web forms
 
Mail
MailMail
Mail
 
Files in php
Files in phpFiles in php
Files in php
 
File upload php
File upload phpFile upload php
File upload php
 
Regex posix
Regex posixRegex posix
Regex posix
 
Encryption in php
Encryption in phpEncryption in php
Encryption in php
 
Authentication methods
Authentication methodsAuthentication methods
Authentication methods
 
Xml schema
Xml schemaXml schema
Xml schema
 
Xml dtd
Xml dtdXml dtd
Xml dtd
 
Xml dom
Xml domXml dom
Xml dom
 
Xhtml
XhtmlXhtml
Xhtml
 
Intro xml
Intro xmlIntro xml
Intro xml
 
Dom parser
Dom parserDom parser
Dom parser
 
Unit 1-subroutines in perl
Unit 1-subroutines in perlUnit 1-subroutines in perl
Unit 1-subroutines in perl
 
Unit 1-uses for scripting languages,web scripting
Unit 1-uses for scripting languages,web scriptingUnit 1-uses for scripting languages,web scripting
Unit 1-uses for scripting languages,web scripting
 
Unit 1-strings,patterns and regular expressions
Unit 1-strings,patterns and regular expressionsUnit 1-strings,patterns and regular expressions
Unit 1-strings,patterns and regular expressions
 
Unit 1-scalar expressions and control structures
Unit 1-scalar expressions and control structuresUnit 1-scalar expressions and control structures
Unit 1-scalar expressions and control structures
 

Dernier

Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
chumtiyababu
 

Dernier (20)

Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptx
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 

Perl names values and variables

  • 2. NAMES IN PERL  Perl manipulates variables which have a name.  A value is assigned to/stored in variable by assignment statement of the form name=value  Perl distinguishes between singular name and plural name. A singular name –holds single item of data– scalar value A plural name for variable – hold collection of data items — an array or hash  Starting special character of variable denotes the kind of thing that name stands for  $ ---- Scalar data  @ ----- Array  % ----- Hash  & ----- Sub routine 6/18/2016 2
  • 3. NAMES IN PERL...  Valid characters are letters,digits,underscores.  First character after special character can be a letter or underscore.  Names may also have non-alphanumeric character after special character. $$,$? (system reserved names in Perl )  Each kind of data has separate namespace.  Special character determine the context in which the name is being used.  In C language a new variable is declared as int i=1; float data[9];  Scope of variable depends on the part of program in which the variable is visible and available for use.  Global scope and local scope.  Variable declaration in perl – $a=5; my $a=10;  A variable comes into existence when declared or first used with special value denoted by undef undef $x; 6/18/2016 3
  • 4. NAMES IN PERL...  use strict ‘var’; (or) use strict;  It tells perl to insist on declaration by placing the line.  At the start of script variables are declared using  my $x,$y; #!/usr/bin/perl @ages = (25, 30, 40); @names = ("John Paul", "Lisa", "Kumar"); print "$ages[0] = $ages[0]n"; print "$ages[1] = $ages[1]n"; print "$ages[2] = $ages[2]n"; print "$names[0] = $names[0]n"; print "$names[1] = $names[1]n"; print "$names[2] = $names[2]n"; 6/18/2016 4
  • 5. A scalar is a single unit of data. Perl recognizes two kinds of scalar data , a String and Numbers . There’s no difference between integers and real numbers both are same. Here is a simple example of using scalar variables − #!/usr/bin/perl $age = 25; # An integer assignment $name = "John Paul"; # A string $salary = 1445.50; # A floating point print "Age = $agen"; print "Name = $namen"; print "Salary = $salaryn"; This will produce the following result − Age = 25 Name = John Paul Salary = 1445.5 Strings are stored as sequence of bytes of unlimited length . Perl is dynamically typed language (System keeps track of whether a variable contains a numeric value or string value).Depending on the context strings are converted to int. Eg: If int/num occurs in String context, operand for string operator , perl will convert it to string Numeric Scalars A scalar is most often either a number or a string. Following example demonstrates the usage of various types of numeric scalars − 6/18/2016 5
  • 6. #!/usr/bin/perl $integer = 200; $negative = -300; $floating = 200.340; $bigfloat = -1.2E-23; # 377 octal, same as 255 decimal $octal = 0377; # FF hex, also 255 decimal $hexa = 0xff; print "integer = $integern"; print "negative = $negativen"; print "floating = $floatingn"; print "bigfloat = $bigfloatn"; print "octal = $octaln"; print "hexa = $hexan"; This will produce the following result − integer = 200 negative = -300 floating = 200.34 bigfloat = -1.2e-23 octal = 255 hexa = String Scalars Following example demonstrates the usage of various types of string scalars. Notice the difference between single quoted strings and double quoted strings − #!/usr/bin/perl $var = "This is string scalar!"; $quote = 'I m inside single quote - $var'; $double = "This is inside single quote - $var"; $escape = "This example of escape -tHello, World!"; print "var = $varn"; print "quote = $quoten"; print "double = $doublen"; print "escape = $escapen"; 6/18/2016 6
  • 7. STRING CONSTANTS/LITERALS  String constant and literals can be enclosed in single or double quotes.  The string is terminated by first next occurrence of quote which started it , so single quoted strings can include double quotes and vice versa.  Single quoted strings are treated as it is- ‘Fridayn’  ‘Friday’--- String  ‘Fridayn’---String with seven characters including last character which is a new line.  n-newline,t-tab,U-uppercase  There is more than one way to choose your own quote  1.quote — q  2.double quote– qq  q /any string/  or q(any string) and qq(any string), qq /any string/ 6/18/2016 7
  • 8. VARIABLES AND ASSIGNMENT  Perl uses – ‘=‘ as the assignment operator. It returns a value. This permits statement like  $b=4+($a=3);  $a=“Burger”;  $b=“Sandwich $a” //$b would give “Sandwich Burger”  $c=“turkey $a”;  Scalar variable names start with--$  $a=“java”;  $b=“${a} script”;//value is javascript 6/18/2016 8
  • 9. <STDIN>  <STDIN>is used for acquiring input from keyboard.If no input is queued perl will wait until a line is typed and the return key pressed.  End-of-file ctrl - D  Unix ctrl - Z  DOS  They cause the return to be undefined, it evaluates to “ “ .  The empty string is treated as false in boolean context. while(<STDIN>){ ..... } To process all statements until the end of file is reached. While(defined <STDIN>){ ... } 6/18/2016 9