scripting languages

27
Scripting Languages Dolores Zage

Upload: benita

Post on 05-Jan-2016

36 views

Category:

Documents


0 download

DESCRIPTION

Scripting Languages. Dolores Zage. What is a script ?. Can mean several things… in programming A program that is interpreted or carried out by another program rather than by a processor Popular scripting languages Perl Rexx JavaScript Tcl/Tk VBScript. What is a script?. In OS - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Scripting Languages

Scripting Languages

Dolores Zage

Page 2: Scripting Languages

What is a script ?

Can mean several things… in programming

A program that is interpreted or carried out by another program rather than by a processor

Popular scripting languages Perl Rexx JavaScript Tcl/Tk VBScript

Page 3: Scripting Languages

What is a script?

In OS list of OS commands that are prestored in file

and performed sequentially by an interpreter In multimedia sequence of instructions that you enter to

indicate how presentation will be presented

Page 4: Scripting Languages

Profile

Easier and faster to code limited capability tie programs together script takes longer to run web scripts normally handle forms of input

and output

Page 5: Scripting Languages

Pro and Cons of Scripting Languages - Users views While I have nothing against specialized scripting languages, it seems more parsimonious to define an appropriate C++ library and use the same language for scripting as for development. Then scripts can be invoked by other scripts in the same manner as servers. In fact, the difference between scripts and servers is all convention and not substance. (Whereas with a specialized scripting language scripts and servers are different species that cannot mix.) This would seem to enable the kind of open growth that is being seen now with World Wide Web scripting languages. (Hot Java is a cleaned-up C++ that works with the Web.)

Page 6: Scripting Languages

Another users view of scripts

– I come at this problem from three related viewpoints: I am the author of a widely-used program, I use many different tasks in my own research, and I help out other researchers using a variety of tasks and packages. This has led me to two related observations about general users :

– 1) they want to be able to accomplish their research with the minimum of interaction with the software.

– 2) they (we) do some really stupid things sometimes.

Page 7: Scripting Languages

So, my plea is the following. By all means try to improve the interoperability of software and all those other good things. Just don't spend so much of the available resources on it that there is nothing left to put together high level scripts/tasks for specific astronomical uses. These scripts/tasks need to operate with the minimum of user input and they need to have enough encoded expertise that they catch cases when the user is probably being stupid. It will do the average user no good to be able to use a task from IRAF followed by one from AIPS++ followed by one from IDL if they don't know that these are the appropriate tasks to use or if they do know about the tasks but they end up using one of them in an invalid regime.

Keith Arnaud Lab. for High Energy Astrophysics NASA/GSFC

Page 8: Scripting Languages

John Ousterhout View of ScriptingScripting: Higher Level Programming for the 21st Century

John Ousterhout Sun Microsystems Laboratories

As we near the end of the 20th century a fundamental change is occurring in the way people write computer programs. The change is a transition from system programming languages such as C or C++ to scripting languages such as Perl or Tcl. Although many people are participating in the change, few people realize that it is occurring and even fewer people know why it is happening. In this talk I will explain why scripting languages will handle many of the programming tasks of the next century better than system programming languages. Scripting languages represent a very different style of programming than system programming languages. They are designed for "gluing" applications, and use typeless approaches to achieve a higher level of programming and more rapid application development. Increases in computer speed and changes in the application mix are making scripting languages more and more important for applications of the future. After presenting the general issues associated with scripting I will discuss how scripting relates to agents, and where scripting does and doesn't make sense for intelligent and mobile agents.

Page 9: Scripting Languages

January 2000, Good Source for Scripting http://www.ddj.com/articles/2000/0001/0001t

oc.htm

Page 10: Scripting Languages

AWK

AT&T text processing awk/sed Perl has taken over

Page 11: Scripting Languages

Perl

Practical Extraction and Reporting Language or Pathologically Eclectic Rubbish Lister

successor to awk it combines shells, awk, sed, grep and C Larry Wall -creator GNU product glue language

Page 12: Scripting Languages

Perl

Originally designed to manipulate text in files, extract data from files, write reports

added: manipulate files, processes, and perform many networking tasks

most popular language for writing CGI scripts (to generate dynamic pages for processing forms0

Page 13: Scripting Languages

What version?

$perl -v This is perl, version 5.00 (our Unix system)

Page 14: Scripting Languages

Perl at the Command Line

Although usually done in scripts, can be executed at the command line for simple tasks such as testing a simple function, a print statement

the -e switch allows Perl to execute Perl statements at the

command line instead of a script

Page 15: Scripting Languages

Command line examples

$perl -e ‘print “hello world\n”;’ -n switch - implicitly loop through the file one line

at a time $perl -ne ‘print’ emp.dat - prints entire file $perl -ne ‘print if/^IGOR/’ emp.dat uses regular expression matching $date | perl -ne ‘print “Today is $_”’ the output of the Unix date command is piped to

Perl and stored in the $_ variable

Page 16: Scripting Languages

Command line examples

$perl -ne ‘print’ < emp.dat input is taken from file emp.dat and output is

sent to the screen $perl -ne ‘print’ < emp.dat > emp.temp input is taken from file emp.dat and output is

sent to emp.temp

Page 17: Scripting Languages

Script setup

List of Perl statements and declarations statements are terminated by ; variables are created anywhere in the script

and if not initialized, automatically get the result 0 or null depending on their context

Perl executes each line only once, when working with files, must use an explicit loop to iterate over the entire file or use the -n ( unlike awk and sed).

Page 18: Scripting Languages

Startup and the #! line

First line must be the #! Followed by the pathname of the directory where the version of Perl resides

#!/usr/local/bin/perl I used the whereis perl Unix command to determine

path tells the kernel what program is interpreting the

script note: you must chmod your script to be executable!

Page 19: Scripting Languages

First Perl

#!/usr/local/bin/perl #my first perl print “Hello world\n”;

$perl -c first.perl - check syntax $chmod +x first.perl - add execute permission $first.perl

Page 20: Scripting Languages

Variables in Perl #!/usr/local/bin/perl $salary=50000; #scalar assignment @months=(Mar,Apr,May); # array assign. %states=( ‘CA’ => ‘California’, ‘IN’ => ‘Indiana’ ); #hash assign. print “$salary\n”; print “@months\n”; print “$months[0],$months[1], $months[2]\n”; print “$states{‘CA’}, $states{‘IN’}\n”; print $x + 3, “\n”;

Page 21: Scripting Languages

Two Dimensional arrays

@matrix = ([3,4,5], [2,5,7], [3,4,5], ); need a nested loop to print out for ($i=0; $i<=2; $i++){ for ($x=0; $x<=2; $x++){ print “$matrix[$i][$x]”; } print “\n”; }

Page 22: Scripting Languages

Records

@record = (“Adam”,[3,4,5], “Mark”, [2,5,7], “John”, [3,4,5], );

print “$record[0], $record[1]->[0]”; print “$record[2], $record[3]->[0]”;

Page 23: Scripting Languages

Other concepts

Message queues, semaphores and shared memory (IPC objects)

Networking features - protocol functions, socket function

Page 24: Scripting Languages

Perl and CGi

#!/usr/local/bin/perl print “content-type: text/html\n\n”: #MIME header print

“<HTML><HEAD><TITLE>CGI/Perl_first_try</TITLE></HEAD>/n”;

… other print commands with associated html commands ..

Print ‘date’; # execute unix date command print “</….></HTML>/n”;

Page 25: Scripting Languages

Tcl/Tk

Big around late 80s with Tk can do easier GUIs John Ousterhout does not excel in anything

Page 26: Scripting Languages

Python

Glue and general purpose stronger OO flavor

Page 27: Scripting Languages

Web pages on general scripting

Script_lang.htm script2.htm