Title: Scripting Languages
1Scripting Languages
- Perl, Python, Unix Shell, VB, JavaScript, etc.
- Glue Languages.
- Typeless.
- Interchangeable Code and Data.
- Interpreted vs. Compiled.
- Rapid Prototyping and short development time.
- Sacrifice execution speed.
- Symbiotic with system programming languages.
2(No Transcript)
3Rise in importance
- GUIs, Internet, Component frameworks
- Advance in scripting technology (JCL -gt Perl)
- Machine speeds are rising (2x every 18 months)
- Change in programming community
- Arguments for and against are common So,
- lets re-enact this over the mailing list !
4Perl
- Initially designed as a glue for Unix.
- A text processor.
- Free, simple, flexible and loaded with features.
- Compiled and Interpreted.
5Singulars and Plurals
- Scalars ident holds a single value.
- Array _at_ident keyed by number
- Hash ident unordered, keyed by string
- Subroutine ident Callable chunk of code
- Typeglob ident anything!
6 mynum 45 realnum 5.6677 scinum
3.44e2 mystr string inter
interpolated mystr noint 'no
interpolation with mystr' expr realnum
scinum stroutput ls print '123' 1,
\n 124 print '123' 1, '\n' 124\n
7 Arrays _at_nums (one, two, three)
nums0 one nums1 two nums2
three (num1, num2, num3) _at_nums
rearranged order (n1, n2, n3) (num2,
num3,num1)
8Hashes daysof week (Sun, Sunday, Mon,
Monday, ..., Sat,
Saturday) daysof week ( Sun gt
Sunday, Mon gt Monday, ..., Sat
gt Saturday) longdayTue
Tuesday
9- Functions
- Subroutines, operators, procedures.
- They all return a value.
- print 123 returns 1
- print nothing returns an undefined value.
10Filehandles open(OLDFILE,"try") open(OLDFILE,
lttry) open(NEWFILE, gtnewtry) open(OLDFILE,
gtgtnewtry) open(PIPE, output-pipe) open(PI
PE, input-pipe ) STDIN, STDOUT, STDERR have
their usual meanings. Typical user input
operation. chop(number ltSTDINgt)
11- Operators
- Arithmetic , - , / , , ,
- String . , x,
- Assignment , op (lvalue op rvalue)
- AutoIncr/decr a, a, --a, a--
- Logical , , !, and, or, not
- Comparison (eq) , ! (ne) , lt(lt), gt(gt),
lt(le), ltgt (cmp) - File test -d, -e, -r , ....(mostly unary and
return boolean)
12- Truth
- Any string except and 0.\
- Any number except 0.
- Any reference. (evaluates to non zero address)
- No undefined value. (evaluates to 0 or null
str.)
13 Control Structures if and unless if
(boolean) ... if (boolean) ... else
... if (boolean) ... elsif (boolean)
... else ... unless(boolean) ...
equivalent to if (not(boolean)) ...
14 Control Structures while and until while
(boolean) ... until (boolean) ...
same as while(not(boolean)) ...
15 Control Structures for and foreach for
(initialization terminating condition, step)
... foreach scalar (_at_list) ... next
and last are very similar to C continue and
break except for ability to handle multilevel
exits. LABEL while (boolean) ...
last LABEL if (boolean) ... next LABEL if
(boolean)