DOC PREVIEW
DREXEL CS 265 - perl_1_tf

This preview shows page 1-2-20-21 out of 21 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

A Brief Introduction to PerlSlide 2IntroductionScalar DataVariablesOperatorsAssignment OperatorArithmetic OperatorsString OperatorsNumeric Comparison OperatorsString Comparison OperatorsTwo Special Features of PerlIf-Else Control StructuresExample: If-Else Control StructureWhile Control StructureExample: While Control StructureStandard InputExampleListsArraysSlide 21Part IIntroductionScalar DataVariables OperatorsIf-Else Control StructuresWhile Control StructuresStandard InputLists and ArraysPerl 1 - Created by Larry Wall in 1987Stable Release: Perl 5.10.1Two basic scalar data types: Numbers and StringsNumbers-Integers and Floating-Point Numbers have the same format.Ex. $v=8222222#v contains value of 8Strings-Sequences of Characters.-Can either be enclosed in single or double quotes.Ex. $v=“a”222222#v contains value of “a”Undef –For Numbers or Strings, there is a special value called undef. This is initially assigned to all variables and acts as a zero for numbers and a null or empty string for strings.A scalar variable holds a single scalar valueNames of any scalar variable must begin with the “$” symbol followed by a Perl identifierEx. $tom, $cs265AssignmentArithmeticStringNumeric ComparisonString Comparison=Ex. $cs = 265+, -, *, /Ex. $c = a + b (Addition)$c = a – b (Subtraction)$c = a * b (Multiplication)$c = a / b (Division)., x. (dot) – String ConcatenationEx. $cl = class, $ro = room, $cl . $ro = classroomx – String MultiplierEx. $cl x 2 = classclass==, !=, <,>,<=,>=eq, ne, lt, gt, le, ge1. Interpolation of scalars into strings◦Any scalar variable inside a double quoted string is replaced by its value. ◦Ex. $example=“example”; print "$example";  prints example2. Automatic conversion between numbers and strings◦Arguments of an arithmetic operator are automatically recognized as numbers, and arguments of a string operator as strings. ◦Ex. $one = 1, $two = 2..◦print $one*$two;  prints 2◦print $one x $two;  prints 11◦print $one . $two  prints 12Conditional Loopif(…){ … } else { … }$expected = “apple”; $given = “pear”;if($expected eq $given){ print “Apple”} else { print “Other Fruit”}Conditional Loopwhile (…) { … }$num = 1;while ($num != 1111) { $num . $num;}Input in Perl is very convenient<STDIN> Ex. Typical Line of Code for input$line=<STDIN> # read a full line from standard input and store it in variable $line$line=<STDIN>; if($line eq "\n"){ print "This was an empty line.\n"; } else { print "This line was not empty.\n"; }Lists are also user friendly in PerlList Literals (representations of lists) ◦Ex. (1,2,3,4) # a list consisting of numbers 1,2,.. 4◦Ex. (1..10) # the same list as the one above, now created by the range operator($a ..$b) - the range determined by current values of $a and $b List Assignment Examples:Arrays are variables storing lists.@num = (1..100) # creates an array “num” with a numbers 1 through 100◦print $num[0] # prints out 1◦print $num[$#num] # prints out the largest index of the


View Full Document

DREXEL CS 265 - perl_1_tf

Download perl_1_tf
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view perl_1_tf and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view perl_1_tf 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?