SlideShare a Scribd company logo
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
Ad

More Related Content

What's hot (20)

Code Optimization
Code OptimizationCode Optimization
Code Optimization
Akhil Kaushik
 
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
sana mateen
 
Unit VI
Unit VI Unit VI
Unit VI
Bhavsingh Maloth
 
Unit 1-perl names values and variables
Unit 1-perl names values and variablesUnit 1-perl names values and variables
Unit 1-perl names values and variables
sana mateen
 
Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)
swapnac12
 
Perl Introduction
Perl IntroductionPerl Introduction
Perl Introduction
Marcos Rebelo
 
Advanced topics in artificial neural networks
Advanced topics in artificial neural networksAdvanced topics in artificial neural networks
Advanced topics in artificial neural networks
swapnac12
 
Learning set of rules
Learning set of rulesLearning set of rules
Learning set of rules
swapnac12
 
Nonrecursive predictive parsing
Nonrecursive predictive parsingNonrecursive predictive parsing
Nonrecursive predictive parsing
alldesign
 
States, state graphs and transition testing
States, state graphs and transition testingStates, state graphs and transition testing
States, state graphs and transition testing
ABHISHEK KUMAR
 
Three address code In Compiler Design
Three address code In Compiler DesignThree address code In Compiler Design
Three address code In Compiler Design
Shine Raj
 
Attribute grammer
Attribute grammerAttribute grammer
Attribute grammer
ahmed51236
 
Developing a Map Reduce Application
Developing a Map Reduce ApplicationDeveloping a Map Reduce Application
Developing a Map Reduce Application
Dr. C.V. Suresh Babu
 
Code generation
Code generationCode generation
Code generation
Aparna Nayak
 
sl slides-unit-1.pptx
sl slides-unit-1.pptxsl slides-unit-1.pptx
sl slides-unit-1.pptx
SRAVANTHISALLARAM1
 
parallel Questions &amp; answers
parallel Questions &amp; answersparallel Questions &amp; answers
parallel Questions &amp; answers
Md. Mashiur Rahman
 
Heuristic Search in Artificial Intelligence | Heuristic Function in AI | Admi...
Heuristic Search in Artificial Intelligence | Heuristic Function in AI | Admi...Heuristic Search in Artificial Intelligence | Heuristic Function in AI | Admi...
Heuristic Search in Artificial Intelligence | Heuristic Function in AI | Admi...
RahulSharma4566
 
Peephole optimization techniques in compiler design
Peephole optimization techniques in compiler designPeephole optimization techniques in compiler design
Peephole optimization techniques in compiler design
Anul Chaudhary
 
Token, Pattern and Lexeme
Token, Pattern and LexemeToken, Pattern and Lexeme
Token, Pattern and Lexeme
A. S. M. Shafi
 
Register allocation and assignment
Register allocation and assignmentRegister allocation and assignment
Register allocation and assignment
Karthi Keyan
 
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
sana mateen
 
Unit 1-perl names values and variables
Unit 1-perl names values and variablesUnit 1-perl names values and variables
Unit 1-perl names values and variables
sana mateen
 
Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)
swapnac12
 
Advanced topics in artificial neural networks
Advanced topics in artificial neural networksAdvanced topics in artificial neural networks
Advanced topics in artificial neural networks
swapnac12
 
Learning set of rules
Learning set of rulesLearning set of rules
Learning set of rules
swapnac12
 
Nonrecursive predictive parsing
Nonrecursive predictive parsingNonrecursive predictive parsing
Nonrecursive predictive parsing
alldesign
 
States, state graphs and transition testing
States, state graphs and transition testingStates, state graphs and transition testing
States, state graphs and transition testing
ABHISHEK KUMAR
 
Three address code In Compiler Design
Three address code In Compiler DesignThree address code In Compiler Design
Three address code In Compiler Design
Shine Raj
 
Attribute grammer
Attribute grammerAttribute grammer
Attribute grammer
ahmed51236
 
Developing a Map Reduce Application
Developing a Map Reduce ApplicationDeveloping a Map Reduce Application
Developing a Map Reduce Application
Dr. C.V. Suresh Babu
 
parallel Questions &amp; answers
parallel Questions &amp; answersparallel Questions &amp; answers
parallel Questions &amp; answers
Md. Mashiur Rahman
 
Heuristic Search in Artificial Intelligence | Heuristic Function in AI | Admi...
Heuristic Search in Artificial Intelligence | Heuristic Function in AI | Admi...Heuristic Search in Artificial Intelligence | Heuristic Function in AI | Admi...
Heuristic Search in Artificial Intelligence | Heuristic Function in AI | Admi...
RahulSharma4566
 
Peephole optimization techniques in compiler design
Peephole optimization techniques in compiler designPeephole optimization techniques in compiler design
Peephole optimization techniques in compiler design
Anul Chaudhary
 
Token, Pattern and Lexeme
Token, Pattern and LexemeToken, Pattern and Lexeme
Token, Pattern and Lexeme
A. S. M. Shafi
 
Register allocation and assignment
Register allocation and assignmentRegister allocation and assignment
Register allocation and assignment
Karthi Keyan
 

Similar to Perl names values and variables (20)

Introduction to perl_lists
Introduction to perl_listsIntroduction to perl_lists
Introduction to perl_lists
Vamshi Santhapuri
 
PERL PROGRAMMING LANGUAGE Basic Introduction
PERL PROGRAMMING LANGUAGE Basic IntroductionPERL PROGRAMMING LANGUAGE Basic Introduction
PERL PROGRAMMING LANGUAGE Basic Introduction
johnboladevice
 
Scalar data types
Scalar data typesScalar data types
Scalar data types
Krasimir Berov (Красимир Беров)
 
Perl slid
Perl slidPerl slid
Perl slid
pacatarpit
 
newperl5
newperl5newperl5
newperl5
tutorialsruby
 
newperl5
newperl5newperl5
newperl5
tutorialsruby
 
Complete Overview about PERL
Complete Overview about PERLComplete Overview about PERL
Complete Overview about PERL
Ravi kumar
 
Introduction to perl_control structures
Introduction to perl_control structuresIntroduction to perl_control structures
Introduction to perl_control structures
Vamshi Santhapuri
 
Lecture 23
Lecture 23Lecture 23
Lecture 23
rhshriva
 
Beginning Perl
Beginning PerlBeginning Perl
Beginning Perl
Dave Cross
 
Tutorial perl programming basic eng ver
Tutorial perl programming basic eng verTutorial perl programming basic eng ver
Tutorial perl programming basic eng ver
Qrembiezs Intruder
 
Perl Scripting
Perl ScriptingPerl Scripting
Perl Scripting
Varadharajan Mukundan
 
Perl intro
Perl introPerl intro
Perl intro
Kanchilug
 
LPW: Beginners Perl
LPW: Beginners PerlLPW: Beginners Perl
LPW: Beginners Perl
Dave Cross
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
tutorialsruby
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
tutorialsruby
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
tutorialsruby
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
tutorialsruby
 
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
 
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
Roy Zimmer
 
Ad

More from sana mateen (20)

Files
FilesFiles
Files
sana mateen
 
PHP Variables and scopes
PHP Variables and scopesPHP Variables and scopes
PHP Variables and scopes
sana mateen
 
Php intro
Php introPhp intro
Php intro
sana mateen
 
Php and web forms
Php and web formsPhp and web forms
Php and web forms
sana mateen
 
Mail
MailMail
Mail
sana mateen
 
Files in php
Files in phpFiles in php
Files in php
sana mateen
 
File upload php
File upload phpFile upload php
File upload php
sana mateen
 
Regex posix
Regex posixRegex posix
Regex posix
sana mateen
 
Encryption in php
Encryption in phpEncryption in php
Encryption in php
sana mateen
 
Authentication methods
Authentication methodsAuthentication methods
Authentication methods
sana mateen
 
Xml schema
Xml schemaXml schema
Xml schema
sana mateen
 
Xml dtd
Xml dtdXml dtd
Xml dtd
sana mateen
 
Xml dom
Xml domXml dom
Xml dom
sana mateen
 
Xhtml
XhtmlXhtml
Xhtml
sana mateen
 
Intro xml
Intro xmlIntro xml
Intro xml
sana mateen
 
Dom parser
Dom parserDom parser
Dom parser
sana mateen
 
Unit 1-subroutines in perl
Unit 1-subroutines in perlUnit 1-subroutines in perl
Unit 1-subroutines in perl
sana mateen
 
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
sana mateen
 
Unit 1-introduction to scripts
Unit 1-introduction to scriptsUnit 1-introduction to scripts
Unit 1-introduction to scripts
sana mateen
 
Unit 1-introduction to perl
Unit 1-introduction to perlUnit 1-introduction to perl
Unit 1-introduction to perl
sana mateen
 
Ad

Recently uploaded (20)

Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
The Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLabThe Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLab
Journal of Soft Computing in Civil Engineering
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
Value Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous SecurityValue Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous Security
Marc Hornbeek
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Journal of Soft Computing in Civil Engineering
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
Introduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptxIntroduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptx
AS1920
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxbMain cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
SunilSingh610661
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
New Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdfNew Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdf
mohamedezzat18803
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
Value Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous SecurityValue Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous Security
Marc Hornbeek
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
Introduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptxIntroduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptx
AS1920
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxbMain cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
SunilSingh610661
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
New Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdfNew Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdf
mohamedezzat18803
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 

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