Perl Variables: Hash Web Programming.

Slides:



Advertisements
Similar presentations
» PHP arrays are lists of values stored in key-value pairs. » Uses of arrays: Many built-in PHP environment variables. Database functions use arrays.
Advertisements

Programming Perls* Objective: To introduce students to the perl language. –Perl is a language for getting your job done. –Making Easy Things Easy & Hard.
Hashes a “hash” is another fundamental data structure, like scalars and arrays. Hashes are sometimes called “associative arrays”. Basically, a hash associates.
7ex.1 Hashes. 7ex.2 Let's say we want to create a phone book... Enter a name that will be added to the phone book: Eyal Enter a phone number:
8.1 Hashes (associative arrays). 8.2 Let's say we want to create a phone book... Enter a name that will be added to the phone book: Dudi Enter a phone.
9.1 Hashes. 9.2 Let's say we want to create a phone book... Enter a name that will be added to the phone book: Ofir Enter a phone number: Enter.
Introduction to Perl Part III By: Cedric Notredame Adapted from (BT McInnes)
Computer Programming for Biologists Class 7 Nov 27 th, 2014 Karsten Hokamp
Scripting Languages Diana Trandab ă ț Master in Computational Linguistics - 1 st year
CSE 143 Lecture 11 Maps Grammars slides created by Alyssa Harding
4 1 Array and Hash Variables CGI/Perl Programming By Diane Zak.
9 1 DBM Databases CGI/Perl Programming By Diane Zak.
11 1 Cookies CGI/Perl Programming By Diane Zak Objectives In this chapter, you will: Learn the difference between temporary and persistent cookies.
Array & Foreach อาร์เรย์และคำสั่งวนลูป. Content 1. Definition and Usage 2. Syntax 3. print_r() Statement 4. For and Foreach 5. Array Functions.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Introduction to Perl Part III By: Bridget Thomson McInnes 6 Feburary 2004.
An Intro to Perl, Pt. 2 Hashes, Foreach Control, and the Split Function.
Introduction to Programming the WWW I CMSC Winter 2003.
5 1 Data Files CGI/Perl Programming By Diane Zak.
CS 330 Class 9 Programming plan for today: More of how data gets into a script Via environment variables Via the url From a form By editing the url directly.
Perl Basics. sh-bang !!!! Every perl program starts with a sh-bang line #!/usr/bin/perl # hello.pl printf “Hello, world!\n”; printf STDOUT “Hello, world!\n”;
Perl Chapter 5 Hashes. Outside of world of Perl, know as associative arrays Also called hash tables Perl one of few languages that has hashes built-in.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
A Few More Functions. One more quoting operator qw// Takes a space separated sequence of words, and returns a list of single-quoted words. –no interpolation.
More Perl Data Types Scalar: it may be a number, a character string, or a reference to another data type. -the sigil $ is used to denote a scalar(or reference)
Department of Electrical and Computer Engineering Introduction to Perl By Hector M Lugo-Cordero August 26, 2008.
8.1 Common Errors – Exercise #3 Assuming something on the variable part of the input file. When parsing a format file (genebank, fasta or any other format),
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Basic Variables & Operators Web Programming1. Review: Perl Basics Syntax ► Comments: start with # (ignored by Perl) ► Statements: ends with ; (performed.
Perl Variables: Array Web Programming1. Review: Perl Variables Scalar ► e.g. $var1 = “Mary”; $var2= 1; ► holds number, character, string Array ► e.g.
Perl Scripting III Arrays and Hashes (Also known as Data Structures) Ed Lee & Suzi Lewis Genome Informatics.
1 PERL Functions. 2 Functions Functions also called subroutines are “free flowing”. The returned value from a function can be interpreted in many different.
CSE 143 Lecture 11: Sets and Maps reading:
2000 Copyrights, Danielle S. Lahmani Foreach example = ( 3, 5, 7, 9) foreach $one ) { $one*=3; } is now (9,15,21,27)
PZ02CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ02CX - Perl Programming Language Design and Implementation.
Chapter 17 Arrays Perl to denote an array, for = (10, 20, 30, 50); Array subscripts are number from 0. Array elements require scalar.
Perl Backticks Hashes printf Variables Pragmas. Backticks.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
PHP using MySQL Database for Web Development (part II)
Indexing Goals: Store large files Support multiple search keys
Lecture 2 BNFO 601.
Python – May 18 Quiz Relatives of the list: Tuple Dictionary Set
Perl Programming Language Design and Implementation (4th Edition)
Arrays in PHP are quite versatile
Arrays An array in PHP is an ordered map
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Miscellaneous Items Loop control, block labels, unless/until, backwards syntax for “if” statements, split, join, substring, length, logical operators,
>> JavaScript: Arrays
Advanced Topics Web Programming.
The relational operators
Perl Variables: Array Web Programming.
Lists in Python.
© Akhilesh Bajaj, All rights reserved.
Introduction to Perl Jarrad Battaglia.
Perl: Arrays, Functions, References, Etc.
Web Systems Development (CSC-215)
Basic Input/Output Web Programming.
Control Structures: for & while Loops
Team Members: Anna Tinnemore Gabriel Neer Yow-Ren Chiang
CGI II: Cookies & Stuff Web Programming.
Pemrosesan Teks Herika Hayurani Sept 19, 2006
Programming Perls* Objective: To introduce students to the perl language. Perl is a language for getting your job done. Making Easy Things Easy & Hard.
Files [Computing] Computing.
PERL: part II hashes, foreach control statements, and the split function By: Kevin Walton.
slides created by Alyssa Harding
PHP PART 2.
Database Programming Using Oracle 11g
LOOPING STRUCTURE Chapter - 7 Padasalai
CGI II: Cookies & Stuff Web Programming.
RANDOM NUMBERS SET # 1:
Presentation transcript:

Perl Variables: Hash Web Programming

Hash (Associative Array) Syntax key and value pair %hash = (key1, value1, key2, value2, ….); Hash Elements $hash{keyN} = valueN; Assigning values intialization %hash = (element list); %hash = @array; %hash = (key1=>value1, key2=>value2, …); assigning values to individual hash element $hash{“key1”} = “value1”; Hash elements are stored in a random order  Example script Web Programming

Hash Functions @keys = keys (%hash); @values = values (%hash); return an array of hash keys @values = values (%hash); return an array of hash values (key,value) = each (%hash); return a key-value pair sequentially delete ($hash{key}); deletes a hash element exists ($hash{key}) returns true if key exists in %hash  Example script Web Programming

Printing Hash print %hash; print join (“:”,%hash); hash is collapsed into an array and then printed i.e. print @hash print join (“:”,%hash); hash collapsed into array is joined and printed i.e. print join (“:”,@hash) while (($key, $value) = each %hash) { print “$key=$value\n”; } foreach $key (sort keys %hash) { print “$key=$hash{$key}\n”; }  Example script Web Programming

Hash Examples Word Count open(IN,$file) || die “can’t open $file”; @lines=<IN>; close IN; foreach $line(@lines) { @words= split(/ +/,$line); foreach $wd(@words) { $wdcnt{$wd}++; } }  Example script Web Programming