DOC PREVIEW
DREXEL CS 265 - Perl_Part_I_eg

This preview shows page 1-2-3-4-5 out of 14 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 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 14 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 14 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 14 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 14 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

An Introduction to Perl – Part IScalar DataScalar Data (cont’d.)VariablesOperatorsOperators (cont’d.)Automatic ConversionStandard Input/OutputControl Structures: if-elseControl Structures: whileLists and ArraysLists and Arrays(cont’d.)Questions?RefrencesEmily GoldbergScalar – holds one piece of data•Numbers:Floating-Point Integer Non-decimal3.11023 -12 0377 octal-2.7e32 3_814_524_705 0xff hex0b11111111 binary•Strings:Single-QuotedDouble-Quoted'hello\nthere' hello\nthere “hello\nthere” hellothere$string="world"; print "hi $string \n!"; hi world!Use $ prefix to denote a variable•Ex.- $_points=5; $name2=‘Larry’;Variable names can contain letters, numbers, and underscores, but may NOT begin with a number.Number OperatorsOperation Operator ExampleAdd +Subtract -Multiply *Divide /Modulus % 10.5%3.2 = 1Exponentiation ** 2**3 = 8Assign =, *=. +=Comparison ==, !=, <,>,<=,>=String OperatorsOperation Operator ExampleConcatenation . "hello"."world" helloworldRepetition x “hello”x3 hellohellohelloComparison eq, ne, lt, gt, le, ge Assignment =, *=. +=, .= $name2.=‘ Lee’larry LeeOperations Results"hello“ . 3 * 5 “hello15"“12” * “3” 36"12fred34" * " 3" 3612 - ”fred” 12Output•Ex. - print "The answer is ", 6 * 7, ".\n";Input•Ex. - $line=<STDIN>;•Remove “\n”- chomp($line);if ($language eq “Perl”){ print “Always use curly braces!” ;}else{ print “ Who knows?!”;}while(defined($line=<STDIN>)){chomp($line); print “This line was: $line \n”; }while(<>){ chomp; print “This line was: $_ \n”; }A list is an ordered collection of scalars. An array is a variable that contains a list.A list with five elements@numbers=(1,2,3,4);@numbers=(1..4);numbers[0]=‘one’;print $numbers[$#numbers]; $a=pop( @numbers);push( @numbers, $a+3);Learning Perl by Randal Schwartz and Tom Phoenix (Via Drexel Library electronic resources)“Perl Basics”


View Full Document

DREXEL CS 265 - Perl_Part_I_eg

Download Perl_Part_I_eg
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_Part_I_eg 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_Part_I_eg 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?