Scripting 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.
Rise in importance ● GUIs, Internet, Component frameworks ● Advance in scripting technology (JCL -> 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 !
Perl ● Initially designed as a glue for Unix. ● A text processor. ● Free, simple, flexible and loaded with features. ● Compiled and Interpreted.
Singulars and Plurals ● Scalars $ident holds a single value. ● keyed by number ● Hash%identunordered, keyed by string ● Subroutine&identCallable chunk of code ● Typeglob*ident anything!
$mynum = 45; $realnum = ; $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
= (“one”, “two”, “three”); $nums[0] = “one”; $nums[1] = “two”; $nums[2] = “three”; ($num1, $num2, $num3) rearranged order ($n1, $n2, $n3) = ($num2, $num3,$num1);
Hashes %daysof week = (“Sun”, “Sunday”, “Mon”, “Monday”,..., “Sat”, “Saturday”); %daysof week = ( “Sun” => “Sunday”, “Mon” => “Monday”,..., “Sat” => “Saturday”); $longday{“Tue”} = “Tuesday”;
Functions ● Subroutines, operators, procedures. ● They all return a value. ● print “123” returns 1 ● print nothing returns an undefined value.
Filehandles open(OLDFILE,"try"); open(OLDFILE, “<try”); open(NEWFILE, “>newtry”); open(OLDFILE, “>>newtry”); open(PIPE, “| output-pipe”); open(PIPE, “input-pipe |”); STDIN, STDOUT, STDERR have their usual meanings. Typical user input operation. chop($number = );
Operators ● Arithmetic+, -, /, *, %, ** ● String., x, ● Assignment =, op= (lvalue op= rvalue) ● AutoIncr/decr++$a, $a++, --$a, $a-- ● Logical &&, ||, !, and, or, not ● Comparison ==(eq), != (ne), (gt), (cmp) ● File test -d, -e, -r,....(mostly unary and return boolean)
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.)
Control Structures – if and unless if (boolean) {... }; if (boolean) {... } else {... }; if (boolean) {... } elsif (boolean) {... } else {... }; unless(boolean) {... }; equivalent to if (not(boolean)) {... };
Control Structures – while and until while (boolean) {... }; until (boolean) {... }; same as while(not(boolean)) {... };
Control Structures – for and foreach for (initialization; terminating condition, step) {... }; foreach $scalar {... } 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); }}