DOC PREVIEW
DREXEL CS 265 - An Intro to Perl

This preview shows page 1-2 out of 6 pages.

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

Unformatted text preview:

An Intro to Perl, Pt. 2Hashes (Associative Arrays)Example HashesHash ControlForeach Control StatementThe Split FunctionAn Intro to Perl, Pt. 2Hashes, Foreach Control, and the Split FunctionHashes (Associative Arrays)•Arrays with string indices•Each index is called a key•Different braces than arrays ({} not [])•Use the % sigil to symbolize a hashExample Hashes•$numbers{“one”}=”1”; Assigns 1 to key “one”•$numbers{“two”}=”2”; (accessed as a scalar)•$numbers{“three”}=”3”;•%numbers=(“one”,”1”,”two”,”2”,”three”,”3”);Creates hash with indices one, two, three and values of 1, 2, and 3Hash Control•while(($key, $value) = each %numbers){print "$key $value\n”;}Prints out individual Key-value pairs for the hashForeach Control Statement•For loop designed for processing arrays, hashes, and lists.•@word=(“This”, “is”, “an”, “array”);•foreach $word (@words){print "$word\n";}@myNames = ('Larry', 'Curly', 'Moe');foreach (@myNames) {print $_ . “\n”;}The Split Function•Splits a string using a specific delimiter•@fields=split " ", $string;If $string = “The quick brown fox”@fields= (“The”, “quick”, “brown”, “fox”)•Default delimiter is a space “ “•$info = "Caine:Michael:Actor:14, Leafy Drive"; @personal = split(/:/,


View Full Document

DREXEL CS 265 - An Intro to Perl

Download An Intro to Perl
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 An Intro to Perl 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 An Intro to Perl 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?