UNIT - 1

PERL PART- II

ATUL NAG LECTURER D E P A R T ME N T O F B I O I N F O R MA T I C S

9/2/2010 BI-535 Comp. Prog. in Bioinfo.

CONDITIONAL AND LOOPING CONSTRUCTS •

If if ( condition ) { ... } elsif ( other condition ) { ... } else { ... }



Program to compare two numbers two strings

8/27/2010 BI-535 Comp. Prog. in Bioinfo.

CONDITIONAL AND LOOPING CONSTRUCTS •

While while ( condition ) { ... }



Program to print odd numbers up to 10

8/27/2010 BI-535 Comp. Prog. in Bioinfo.

CONDITIONAL AND LOOPING CONSTRUCTS •

for for ($i = 0; $i <= $max; $i++) { ... }

• Program to write multiplication table for 7.

8/27/2010 BI-535 Comp. Prog. in Bioinfo.

USER INPUT AND CHOMP OPERATOR print “Enter a number:”; $number=; chomp($number);



chomp works on a variable, and the variable has to hold a string. If the string ends in a newline character, chomp can get rid of the newline.



Program to take 2 user input numbers and print greater number.

8/27/2010 BI-535 Comp. Prog. in Bioinfo.

ARRAYS •

Assigning values



Access values



Interpolation of Arrays to strings



foreach loop



in list context

9/2/2010 BI-535 Comp. Prog. in Bioinfo.

ARRAYS •

Arrays : An array represents a list of values: my @animals = ("camel", "llama", "owl"); my @numbers = (23, 42, 69); my @mixed = ("camel", 42, 1.23);



Arrays are zero-indexed. Here's how you get at elements in an array: print $animals[0]; # prints "camel" print $animals[1]; # prints "llama"



The special variable $#array tells you the index of the last element of an array: print $mixed[$#mixed]; # last element, prints 1.23

8/27/2010 BI-535 Comp. Prog. in Bioinfo.

ARRAYS •

The elements we're getting from the array start with a $ because we're getting just a single value out of the array -- you ask for a scalar, you get a scalar.



To get multiple values from an array: @animals[0,1]; # gives ("camel", "llama"); @animals[0..2]; # gives ("camel", "llama", "owl"); @animals[1..$#animals]; # gives all except the first element



This is called an "array slice".



You can do various useful things to lists: my @sorted = sort @animals; my @backwards = reverse @numbers;



There are a couple of special arrays too, such as @ARGV (the command line arguments to your script) and @_ (the arguments passed to a subroutine).

8/27/2010 BI-535 Comp. Prog. in Bioinfo.

ASSIGNING VALUES •

Using the qw operator @arr = qw /1 2 3 4 5/; @names = qw /john mary joy jacob/;

#!/usr/bin/perl use warnings; use strict; my @array = (4, 6, 3, 9, 12, 10); print @array, "\n"; print "@array\n";

9/2/2010 BI-535 Comp. Prog. in Bioinfo.

#!/usr/bin/perl use warnings; use strict; my @array = (1, 3, 5, 7, 9); print @array[1];

#!/usr/bin/perl use warnings; use strict; my @array; my $scalar; @array = qw(Mon Tue Wed Thu Fri Sat Sun); $scalar = @array; print "Array is @array \n Scalar is $scalar\n"; 9/2/2010 BI-535 Comp. Prog. in Bioinfo.

#!/usr/bin/perl use warnings; use strict; my @months = qw(Jan Feb Mar May Apr Jun Jul Aug Sep Oct Nov Dec); print "@months[3..5]"; # Swap April and May @months[3,4] = @months[4,3]; #!/usr/bin/perl use warnings; use strict; my @array = qw(alpha bravo charlie delta); print "Scalar value : ", scalar @array, "\n"; print "Highest element: ", $#array, "\n";

9/2/2010 BI-535 Comp. Prog. in Bioinfo.

FOREACH LOOP •

able to process an entire array or list.



The foreach loop steps through a list of values, executing one iteration (time through the loop) for each value #!/usr/bin/perl use warnings; use strict; my @array = qw(America Asia Europe Africa); my $element; foreach $element (@array) { print $element, "\n"; }

9/2/2010 BI-535 Comp. Prog. in Bioinfo.

PUSH /POP #!/usr/bin/perl use warnings; use strict; my $hand; my @pileofpaper = ("letter", "newspaper", "gas bill", "notepad"); print "@pileofpaper\n"; $hand = pop @pileofpaper; print " $hand \n"; print "Left: @pileofpaper\n"; pop @pileofpaper; push @pileofpaper, $hand; push @pileofpaper, "leaflet", "bank statement"; print "Left: @pileofpaper\n";

9/2/2010 BI-535 Comp. Prog. in Bioinfo.

SHIFT /UNSHIFT #!/usr/bin/perl use warnings; use strict; my @array = (); unshift(@array, "first"); print "Array is now: @array\n"; unshift @array, "second", "third"; print "Array is now: @array\n"; shift @array ; print "Array is now: @array\n";

9/2/2010 BI-535 Comp. Prog. in Bioinfo.

SORT #!/usr/bin/perl use warnings; use strict; my @unsorted = (1, 2, 11, 24, 3, 36, 40, 4); my @sorted = sort @unsorted; print "Sorted: @sorted\n"; #!/usr/bin/perl use warnings; use strict; my @unsorted = (1, 2, 11, 24, 3, 36, 40, 4); my @string = sort { $a cmp $b } @unsorted; print "String sort: @string\n"; my @number = sort { $a <=> $b } @unsorted; print "Numeric sort: @number\n"; 9/2/2010 BI-535 Comp. Prog. in Bioinfo.

PERL part- iI -

Sep 2, 2010 - Here's how you get at elements in an array: print $animals[0]; # prints "camel" print $animals[1]; # prints "llama". • The special variable $#array ...

272KB Sizes 1 Downloads 293 Views

Recommend Documents

Perl and Undecidability: Perl Undecidable
that would generate a parser from any grammar describable in. BNF. No such tool is in ... —they assume something, and show that the assumption creates ..... It's available as a free download: http://www.lulu.com/content/933192. You can ...

Part - II Java.pdf
... check whether it is an. Armstrong number or not. J3. Page 1. Whoops! There was a problem loading this page. Part - II Java.pdf. Part - II Java.pdf. Open. Extract.

Perl and Undecidability: Perl Undecidable
push @ancestry, $found->{'Parent'}->{'Name'}; www.theperlreview.com. Fall 2008 • 23 by Jeffrey Kegler [email protected]. Perl and Undecidability: Perl Undecidable. This is the last of three articles based on a formal proof of Perl's unparseabil

PART I Accounting for Managers PART II Financial ...
Introduction to Financial Accounting-Rules Concepts and Conventions.Structure and contents of ... Financial Products & Services. Money Market & Capital ...

Mastering Algorithms with Perl
that have a separate row for each hour of the day, and ones that squeeze a year or two ...... AT&T Research, http://www. research. att. com/sw/tools/graphviz/.

Part II RNN+LSTM.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item.

THE ZAGIER POLYNOMIALS. PART II: ARITHMETIC PROPERTIES ...
Feb 5, 2013 - [1] M. Abramowitz and I. Stegun. Handbook of Mathematical Functions with Formulas, Graphs and Mathematical Tables. Dover, New York, 1972. [2] H. Alzer. On some inequalities for the gamma and psi functions. Math. Comp., 66:373–389,. 19

part ii: studies on consonants
The notion of perceived similarity between nonnative sounds and corresponding native phonological categories is widely recognized as an important element for any account of L2 speech perception. In psycholinguistic models such as Flege's Speech Learn

2ndYear-Part-II-Sanskrit.pdf
2ndYear-Part-II-Sanskrit.pdf. 2ndYear-Part-II-Sanskrit.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying 2ndYear-Part-II-Sanskrit.pdf. Page 1 of 6.

1stYear-Part-II-Telugu.pdf
Ñ ̈Ù#ifi"åÇ ̈ÏO âߢã ̈Î ã ̈=∞‡`«"Õ∞#x 1875= ã ̈O=`«û~°OÖ' XHõ z#fl Ñ ̈Ùã ̈ÎHÍxfl ¢"åã≤. ¢Ñ ̈Hõ\ ̃OKÃ¥~°∞. P Ñ ̈Ùã ̈ÎHõO ¢Ñ ̈Hõ\ ̃OK«|_ç#Ñ ...

1stYear-Part-II-Hindi.pdf
Page 1 of 2. MODEL QUESTION PAPER. PART - II. HINDI PAPER - I. (Second Language). Time : 3 hours Max. Marks : 100.

quimica II part 1.pdf
23. 30. 36. I. Page 3 of 93. quimica II part 1.pdf. quimica II part 1.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying quimica II part 1.pdf. Page 1 of 93.

Henry IV, Part II
SERVANT He, my lord: but he hath since done good service at Shrewsbury; and, as I hear, is now ... FALSTAFF I would it were otherwise; I would my means were greater, and my waist slenderer. ...... Stay but a little; for my cloud of dignity.

quimica II part 2.pdf
cambios en nuestro cuerpo... Edited with the trial version of. Foxit Advanced PDF Editor. To remove this notice, visit: www.foxitsoftware.com/shopping. Page 1 of ...

PART I Module I: Module II
networks,sinusoidal steady state analysis,resonance,basic filter concept,ideal current ... spherical charge distribution,Ampere's and Biot-Savart's law,Inductance ...

Informe Castor part II - IGME.pdf
Informe Castor part II - IGME.pdf. Informe Castor part II - IGME.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying Informe Castor part II - IGME.pdf.

lte part ii: radio access - IEEE Xplore
was to reduce user plane latency to less than 10 ms and .... editorial team would like to thank our companies for pro- .... tions and real-time software. He is the ...

Part 2 Section II Guide.pdf
Guide to Worker Safety and Health in the Marijuana Industry: 2017 51. Section II: Safety and Health Program Plans. II.1 Hazard communication plan. The Hazard ...

part i and part ii district co-operative bank part i-questions based on ...
promotion-Media relations-Community relations. ... Implementing PR Campaigns-Evaluation of Feedback. ... Social Welfare Legislations and Programmes.

Perl Post Install Tests - GitHub
Apr 10, 2013 - CPAN/Perl community has usually been good at preserving backwards compatibility ... and installed. ▻ Writing a best practices guide for tests ...

Perl for Beginners
services company. ... for Web development – Web pages are HTML text files. .... application such as Word – files created via WP apps contain a lot of extra, ...