Basic Variables & Operators Web Programming1. Review: Perl Basics Syntax ► Comments: start with # (ignored by Perl) ► Statements: ends with ; (performed.

Slides:



Advertisements
Similar presentations
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Master Manipulator perl Perl is.
Advertisements

1 *Copyright © 2002 Pearson Education, Inc.. 2 Web Wizard’s Guide to CGI/Perl David Lash Chapter 3 Perl Basics.
1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Scalar Variables Start the file with: #! /usr/bin/perl –w No spaces or newlines before the the #! “#!” is sometimes called a “shebang”. It is a signal.
Announcements Quiz 1 Next Week. int : Integer Range of Typically -32,768 to 32,767 (machine and compiler dependent) float : Real Number (i.e., integer.
Practical Extraction & Report Language Picture taken from
1ex.1 Perl Programming for Biology Exercise 1 The Bioinformatics Unit G.S. Wise Faculty of Life Science Tel Aviv University, Israel March 2009 Eyal Privman.
Introduction to Perl Software Tools. Slide 2 Introduction to Perl l Perl is a scripting language that makes manipulation of text, files, and processes.
Guide To UNIX Using Linux Third Edition
JavaScript, Third Edition
CSci 142 Data and Expressions. 2  Topics  Strings  Primitive data types  Using variables and constants  Expressions and operator precedence  Data.
Computer Programming for Biologists Class 2 Oct 31 st, 2014 Karsten Hokamp
Chapter 4 – The Building Blocks Data Types Literals Variables Constants.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
JavaScript – Part II Data Types and Operations George Mason University June 3, 2010.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
2440: 211 Interactive Web Programming Expressions & Operators.
STRING Dong-Chul Kim BioMeCIS UTA 10/7/
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Chapter 2: Using Data.
C Derived Languages C is the base upon which many build C++ conventions also influence others *SmallTalk is where most OOP comes Java and Javascript have.
Chapter 2 Elementary Programming
Perl Practical(?)‏ Extraction and Report Language.
The Grammar of JavaScript.  Each line of a script is a statement  An instruction that JavaScript can evaluate (make sense of)  Ends with a semicolon;
COMP519: Web Programming Autumn 2010 Perl Tutorial: The very beginning  A basic Perl Program The first line Comments and statements Simple printing 
Perl: Lecture 1 The language. What Perl is Merger of Unix tools – Very popular under UNIX – shell, sed, awk Programming language – C syntax Scripting.
CS346 Javascript -3 Module 3 JavaScript Variables.
Computer Engineering 1 st Semester Dr. Rabie A. Ramadan 3.
Strings, output, quotes and comments
IFS Intro to Data Management Chapter 5 Getting More Than Simple Columns.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
 2000 Deitel & Associates, Inc. All rights reserved. Outline 8.1Introduction 8.2A Simple Program: Printing a Line of Text in a Web Page 8.3Another JavaScript.
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
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”;
JavaScript. JavaScript is the programming language of HTML and the Web. Easy to learn One of the 3 languages of all developers MUST learn: 1. HTML to.
Chapter 2 Variables.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
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.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
JavaScript 1 COE 201- Computer Proficiency. Introduction JavaScript scripting language ▫Originally created by Netscape ▫Facilitates disciplined approach.
Perl Variables: Array Web Programming1. Review: Perl Variables Scalar ► e.g. $var1 = “Mary”; $var2= 1; ► holds number, character, string Array ► e.g.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
FP512 WEB PROGRAMMING 1 PREPARED BY: PN. NUR SYUHADA BINTI MOHAMAD.
Introduction to Programming the WWW I CMSC Winter 2004 Lecture 7.
Interpolation Variable Interpolation, Backslash Interpolation.
Session 2: PHP Language Basics iNET Academy Open Source Web Development.
Literals A literal (sometimes called a constant) is a symbol which evaluates to itself, i.e., it is what it appears to be. Examples: 5 int literal
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Chapter 16 Introduction to Perl Perl (Practical Extraction and Report Language) Developed by Larry Wall as a Unix scripting language. Popular server-side.
>> Introduction to JavaScript
Chapter 2 Variables.
Chapter 6 JavaScript: Introduction to Scripting
Programming Basics Web Programming.
Perl Variables: Array Web Programming.
Control Structures: if Conditional
An Introduction to Perl
Basic Input/Output Web Programming.
Chapter 2 Variables.
“If you can’t write it down in English, you can’t code it.”
elementary programming
JavaScript: Introduction to Scripting
Chapter 2 Variables.
Understanding Variables
Lexical Elements & Operators
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Basic Variables & Operators Web Programming1

Review: Perl Basics Syntax ► Comments: start with # (ignored by Perl) ► Statements: ends with ; (performed by Perl) ► print: writes to standard output print “My name is $name\n”; print (“My name is ”,$name,”\n”); ► : reads 1 line from standard input Running Perl ► perl [-switch] program_name ► program_name #!/usr/bin/perl at the first line chmod 755 filename Web Programming 2

Perl Variables Scalar ► e.g. $var1 = “Mary”; $var2= 1; ► holds number, character, string Array ► = (“Mary”,”Tom”); ► holds a list of scalars ► $array1[0]=“Mary”; $array1[1]=“Tom”; Associative array (i.e. hash) ► e.g. %hash1 = (“Mary”,”F”,”Tom”,”M”); ► holds key-value scalar pairs ► $hash1{“Mary”}=“F”; $hash1{“Tom”}=“M”; Web Programming 3

Scalar Variable: syntax Syntax ► first character must be $. ► second character must be a letter. ► can consist of only letters, digits, or underscore ► case-sensitive ► can be as long as you want (within reason). Assigning values to scalar variables ► $first_name = “Sam”; $last_name = ; $name = “$first_name $last_name”; $a = 5; $b = $a + 3; Web Programming 4

Working with numbers Arithmetic operators  Example script Example script ► add (+), subtract (-), multiply (*), divide (/) ► mod (%), power (**) ► increment (++, +=), decrement (--, -=) $a++; # increment $a by 1 $a+=2;# $a = $a+2; Limitations  Example script Example script ► limited number of digits can be stored ► use a format e.g. printf (“%.2f”,3.3333); Web Programming 5

Working with strings String operators ► concatenation: $name = “Kiduk”. “ ”; $name.= “Yang”;# $name == “Kiduk Yang” ► repeat: $line= “-” x 10; # $line == “ ” String functions ► length($string); ► substr($string,offset,length) returns a substring of $string starting at offset for length $lastname= substr($name,6,4); ► chop($string) cuts the last character of a string ► chomp ($string) cuts the last character only if it is a line break  Example script Example script Web Programming 6

Scalar Variable: advanced Escape sequences ► consists of backslash (\) and a character ► must be inside double quotes to use backslash or double quote inside double quotes, precede it with a backslash (i.e. \\, \”) ► \nnewline \ttab \uchange next character to uppercase \lchange next character to lowercase \Uchange all following characters to uppercase \Lchange all following characters to lowercase \Eend the effect of \U, \L Initial value of a scalar variable is null. Character and numeric scalars are interchangeable. ► $a=1; $a=“1”; ► null value is converted to zero in arithmetic operations.  Example script Example script Web Programming 7