Introduction to Perl Programming www.collaborationtech.co.in Bengaluru INDIA Presentation By Ramananda M.S Rao
Content Content Overview Get Started Functions & Subroutines Regular Expressions and Patterns Basic Input and Output Formatting and Reporting System Interaction and Process OOPS Concepts Modules ,Packages and Namespaces Project About Us www.collaborationtech.co.in
Overview  Perl is an interpreted language, meaning that a control program that understands the semantics of the language and its components (the interpreter) executes program components individually as they are encountered in the control flow.  Interpreted execution makes Perl flexible, convenient, and fast for programming, with some penalty paid in execution speed.  Perl programs are often called scripts because of its historical development as an extension of the Unix command-level command scripting notations. www.collaborationtech.co.in
Get Started #!/usr/bin/perl # This will print "Hello, World" print "Hello, worldn"; #!/usr/bin/perl print("Hello, worldn"); print "Hello, worldn"; #!/usr/bin/perl print "Hello, worldn"; print 'Hello, worldn'; www.collaborationtech.co.in
Data Types #!/usr/bin/perl $number = 2; $st1 = ‘one fine $number day’; $st2 = “$number fine day n”; print $st2; print “$st1n”; #!/usr/bin/perl $v1 = 127; $v1 = $v1 . ", and more !!"; # . Indicates to concatenate two data print $v1, “n”; $v1 = 127; print $v1 + "151 ", "n"; print $v1 + ", and more !!", "n"; www.collaborationtech.co.in
Data Types #!/usr/bin/perl my @array = (10, 20, 30); # Assign list variables to scalar variables my $scalar1; my $scalar2; my $scalar3; ($scalar1, $scalar2, $scalar3) = @array; print "Scalar one is $scalar1n"; print "Scalar two is $scalar2n"; print "Scalar three is $scalar3n"; Adding to an Array #!/usr/bin/perl # addelem.pl use warnings; use strict; my @array1 = (1, 2, 3); my @array2 = (@array1, 4, 5, 6); print "@array2n"; @array2 = (3, 5, 7, 9); @array2 = (1, @array2, 11); print "@array2n"; >perl addelem.pl 1 2 3 4 5 6 1 3 5 7 9 11 www.collaborationtech.co.in
Control Structure If / elsif / else if ($thresh < 10) { # … the ‘then’ block of the conditional } elsif ($thresh < 20) { # the next block in the decision tree } elsif ($thresh < 40) { # and the next… } else { # the final clause catches what falls through } #!/usr/bin/perl # conditional.pl use strict; use warnings; my ($x, $y) = @ARGV; if ($x == $y) { print "equaln"; } else { print "not equaln"; } www.collaborationtech.co.in
Functions and Subroutines func2.pl: firstSub(1, 2, 3, 4, 5, 6); firstSub(1..3); firstSub("A".."Z"); sub firstSub() { $numParameters = @_ ; print("The number of parameters is $numParametersn"); } func4.pl|: @array = (0..5); print("Before function call, array = @arrayn"); firstSub(@array); print("After function call, array = @arrayn"); sub firstSub{ $_[0] = "A"; $_[1] = "B";} This program prints: Before function call, array = 0 1 2 3 4 5 After function call, array = A B 2 3 4 5} www.collaborationtech.co.in
Functions and Subroutines #!/usr/bin/perl # gc.pl use strict; use warnings; while (my $seq = <>) { chomp($seq); gc($seq); 8. } sub gc { my ($seq) = @_; $seq = uc($seq); # convert to upper case to be sure my $g = $seq =~ tr/G/G/; my $c = $seq =~ tr/C/C/; my $gc = ($g + $c) / length($seq); print "GC% = $gcn"; } }; www.collaborationtech.co.in
Modules  A module is a package contained within an external file of the same name .pm extension file MyMod.pm: package MyMod; #no shebang!! use strict; use warnings; our ($foo, $bar, $baz); ($foo, $bar) = split /s+/, 'Hello World'; $baz = 42; 1; www.collaborationtech.co.in
Packages #!/usr/bin/perl use warnings; #note no use strict! $foo = 'Hello'; #sets $main::foo package Bar; $foo = 'World'; #sets $Bar::foo package Lalli; print "$main::foo $Bar::foon"; prints "Hello Worldn" www.collaborationtech.co.in
Follow us on Social Facebook: https://www.facebook.com/collaborationtechnologies/ Twitter : https://twitter.com/collaboration09 Google Plus : https://plus.google.com/100704494006819853579 LinkedIn : https://www.linkedin.com/in/ramananda-rao-a2012545 Instagram : https://instagram.com/collaborationtechnologies YouTube : https://www.youtube.com/channel/UCm9nK56LRbWSqcYWbzs8CUg Skype : facebook:ramananda.rao.7 WhatsApp : +91 9886272445 www.collaborationtech.co.in THANK YOU
About Us

Introduction to Perl Programming

  • 1.
    Introduction to PerlProgramming www.collaborationtech.co.in Bengaluru INDIA Presentation By Ramananda M.S Rao
  • 2.
    Content Content Overview Get Started Functions &Subroutines Regular Expressions and Patterns Basic Input and Output Formatting and Reporting System Interaction and Process OOPS Concepts Modules ,Packages and Namespaces Project About Us www.collaborationtech.co.in
  • 3.
    Overview  Perl isan interpreted language, meaning that a control program that understands the semantics of the language and its components (the interpreter) executes program components individually as they are encountered in the control flow.  Interpreted execution makes Perl flexible, convenient, and fast for programming, with some penalty paid in execution speed.  Perl programs are often called scripts because of its historical development as an extension of the Unix command-level command scripting notations. www.collaborationtech.co.in
  • 4.
    Get Started #!/usr/bin/perl # Thiswill print "Hello, World" print "Hello, worldn"; #!/usr/bin/perl print("Hello, worldn"); print "Hello, worldn"; #!/usr/bin/perl print "Hello, worldn"; print 'Hello, worldn'; www.collaborationtech.co.in
  • 5.
    Data Types #!/usr/bin/perl $number =2; $st1 = ‘one fine $number day’; $st2 = “$number fine day n”; print $st2; print “$st1n”; #!/usr/bin/perl $v1 = 127; $v1 = $v1 . ", and more !!"; # . Indicates to concatenate two data print $v1, “n”; $v1 = 127; print $v1 + "151 ", "n"; print $v1 + ", and more !!", "n"; www.collaborationtech.co.in
  • 6.
    Data Types #!/usr/bin/perl my @array= (10, 20, 30); # Assign list variables to scalar variables my $scalar1; my $scalar2; my $scalar3; ($scalar1, $scalar2, $scalar3) = @array; print "Scalar one is $scalar1n"; print "Scalar two is $scalar2n"; print "Scalar three is $scalar3n"; Adding to an Array #!/usr/bin/perl # addelem.pl use warnings; use strict; my @array1 = (1, 2, 3); my @array2 = (@array1, 4, 5, 6); print "@array2n"; @array2 = (3, 5, 7, 9); @array2 = (1, @array2, 11); print "@array2n"; >perl addelem.pl 1 2 3 4 5 6 1 3 5 7 9 11 www.collaborationtech.co.in
  • 7.
    Control Structure If /elsif / else if ($thresh < 10) { # … the ‘then’ block of the conditional } elsif ($thresh < 20) { # the next block in the decision tree } elsif ($thresh < 40) { # and the next… } else { # the final clause catches what falls through } #!/usr/bin/perl # conditional.pl use strict; use warnings; my ($x, $y) = @ARGV; if ($x == $y) { print "equaln"; } else { print "not equaln"; } www.collaborationtech.co.in
  • 8.
    Functions and Subroutines func2.pl: firstSub(1,2, 3, 4, 5, 6); firstSub(1..3); firstSub("A".."Z"); sub firstSub() { $numParameters = @_ ; print("The number of parameters is $numParametersn"); } func4.pl|: @array = (0..5); print("Before function call, array = @arrayn"); firstSub(@array); print("After function call, array = @arrayn"); sub firstSub{ $_[0] = "A"; $_[1] = "B";} This program prints: Before function call, array = 0 1 2 3 4 5 After function call, array = A B 2 3 4 5} www.collaborationtech.co.in
  • 9.
    Functions and Subroutines #!/usr/bin/perl #gc.pl use strict; use warnings; while (my $seq = <>) { chomp($seq); gc($seq); 8. } sub gc { my ($seq) = @_; $seq = uc($seq); # convert to upper case to be sure my $g = $seq =~ tr/G/G/; my $c = $seq =~ tr/C/C/; my $gc = ($g + $c) / length($seq); print "GC% = $gcn"; } }; www.collaborationtech.co.in
  • 10.
    Modules  A moduleis a package contained within an external file of the same name .pm extension file MyMod.pm: package MyMod; #no shebang!! use strict; use warnings; our ($foo, $bar, $baz); ($foo, $bar) = split /s+/, 'Hello World'; $baz = 42; 1; www.collaborationtech.co.in
  • 11.
    Packages #!/usr/bin/perl use warnings; #noteno use strict! $foo = 'Hello'; #sets $main::foo package Bar; $foo = 'World'; #sets $Bar::foo package Lalli; print "$main::foo $Bar::foon"; prints "Hello Worldn" www.collaborationtech.co.in
  • 12.
    Follow us onSocial Facebook: https://www.facebook.com/collaborationtechnologies/ Twitter : https://twitter.com/collaboration09 Google Plus : https://plus.google.com/100704494006819853579 LinkedIn : https://www.linkedin.com/in/ramananda-rao-a2012545 Instagram : https://instagram.com/collaborationtechnologies YouTube : https://www.youtube.com/channel/UCm9nK56LRbWSqcYWbzs8CUg Skype : facebook:ramananda.rao.7 WhatsApp : +91 9886272445 www.collaborationtech.co.in THANK YOU
  • 13.