Top Banner
Introduction to Perl Programming www.collaborationtech.co.in Bengaluru INDIA Presentation By Ramananda M.S Rao
13

Introduction to Perl Programming

Apr 13, 2017

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to Perl Programming

Introduction to Perl Programming

www.collaborationtech.co.inBengaluru INDIA

Presentation By Ramananda M.S Rao

Page 2: Introduction to Perl Programming

ContentContentOverviewGet StartedFunctions & SubroutinesRegular Expressions and PatternsBasic Input and OutputFormatting and ReportingSystem Interaction and ProcessOOPS ConceptsModules ,Packages and NamespacesProjectAbout Us

www.collaborationtech.co.in

Page 3: Introduction to Perl Programming

OverviewPerl 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

Page 4: Introduction to Perl Programming

Get Started#!/usr/bin/perl# This will print "Hello, World"print "Hello, world\n";#!/usr/bin/perlprint("Hello, world\n");print "Hello, world\n";#!/usr/bin/perlprint "Hello, world\n";print 'Hello, world\n';

www.collaborationtech.co.in

Page 5: Introduction to Perl Programming

Data Types#!/usr/bin/perl$number = 2; $st1 = ‘one fine $number day’; $st2 = “$number fine day \n”; print $st2; print “$st1\n”;

#!/usr/bin/perl$v1 = 127; $v1 = $v1 . ", and more !!"; # . Indicates to concatenate two dataprint $v1, “\n”; $v1 = 127; print $v1 + "151 ", "\n"; print $v1 + ", and more !!", "\n";

www.collaborationtech.co.in

Page 6: Introduction to Perl Programming

Data Types#!/usr/bin/perl my @array = (10, 20, 30); # Assign list variables to scalar variablesmy $scalar1; my $scalar2; my $scalar3;($scalar1, $scalar2, $scalar3) = @array;print "Scalar one is $scalar1\n";print "Scalar two is $scalar2\n";print "Scalar three is $scalar3\n";Adding to an Array#!/usr/bin/perl# addelem.pluse warnings; use strict;my @array1 = (1, 2, 3);my @array2 = (@array1, 4, 5, 6);print "@array2\n";@array2 = (3, 5, 7, 9);@array2 = (1, @array2, 11);print "@array2\n";>perl addelem.pl1 2 3 4 5 61 3 5 7 9 11

www.collaborationtech.co.in

Page 7: Introduction to Perl Programming

Control StructureIf / 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.pluse strict; use warnings;my ($x, $y) = @ARGV;if ($x == $y) { print "equal\n"; } else { print "not equal\n"; }

www.collaborationtech.co.in

Page 8: Introduction to Perl Programming

Functions and Subroutinesfunc2.pl: firstSub(1, 2, 3, 4, 5, 6);firstSub(1..3);firstSub("A".."Z");sub firstSub() { $numParameters = @_ ; print("The number of parameters is $numParameters\n"); }func4.pl|: @array = (0..5);print("Before function call, array = @array\n");firstSub(@array);print("After function call, array = @array\n"); sub firstSub{ $_[0] = "A"; $_[1] = "B";} This program prints: Before function call, array = 0 1 2 3 4 5After function call, array = A B 2 3 4 5}

www.collaborationtech.co.in

Page 9: Introduction to Perl Programming

Functions and Subroutines#!/usr/bin/perl# gc.pluse strict; use warnings;while (my $seq = <>) {chomp($seq);gc($seq); 8. } sub gc {my ($seq) = @_;$seq = uc($seq); # convert to upper case to be suremy $g = $seq =~ tr/G/G/;my $c = $seq =~ tr/C/C/;my $gc = ($g + $c) / length($seq);print "GC% = $gc\n"; } };

www.collaborationtech.co.in

Page 10: Introduction to Perl Programming

Modules A module is a package contained within an external

file of the same name.pm extensionfile 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

Page 11: Introduction to Perl Programming

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::foo\n";prints "Hello World\n"

www.collaborationtech.co.in

Page 12: Introduction to Perl Programming

Follow us on SocialFacebook: https://www.facebook.com/collaborationtechnologies/Twitter : https://twitter.com/collaboration09Google Plus : https://plus.google.com/100704494006819853579LinkedIn : https://www.linkedin.com/in/ramananda-rao-a2012545Instagram : https://instagram.com/collaborationtechnologiesYouTube : https://www.youtube.com/channel/UCm9nK56LRbWSqcYWbzs8CUgSkype : facebook:ramananda.rao.7WhatsApp : +91 9886272445

www.collaborationtech.co.in

THANK YOU

Page 13: Introduction to Perl Programming

About Us