ebook img

The World of Scripting Languages (Worldwide Series in Computer Science) PDF

507 Pages·2000·34.38 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview The World of Scripting Languages (Worldwide Series in Computer Science)

Bu Culinary chitectul'e Computer Interest Life Sciences B p Accountlng '- Mathematics Self-I mp rovement Engineering e Psychology Interior Design )1 Chemistry WILEY JOSSEY-BASS PFEIFFER J.K.LASSER CAPSTONE WILEY-LISS WILEY-VCH WILEY-INTERSCIENCE The World of Scripting Languages WORLDWIDE SERIES IN COMPUTER SCIENCE Series Editors Professor David Barron, Southampton University, UK Professor Peter Wegner, Brown University, USA The Worldwide series in Computer Science has been created to publish textbooks which both address and anticipate the needs of an ever evolving curriculum thereby shaping its future. It is for undergraduates majoring in Computer Science and practitioners who need to reskill. Its philosophy derives from the conviction that the discipline of computing needs to produce technically skilled who will inevitably and possibly invent, radically new technologies throughout their future careers. New media will be used innovatively to support high quality texts written by leaders in the field. Books in Series Arr.lmt~ra~ll, Computer Graphics for Java Programmers Ammeraal, c++ for Programmers 3rd Edition Ben-Ari, Ada for Software Engineers Gollmann, Computer Security Goodrich & Tamassia, Data Structures and Algorithms in Java Kotonya & Sommerville, Requirements Engineering: Processes and Techniques Lowe & Hall, Hypermedia & the Web: An Engineering Approach & Kramer, Concurrency: State Models and Java Programs Peters, Software Engineering: An Engineering Approach Preiss, Data Structures and Algorithms with Object-Oriented Design Patterns in C++ Preiss, Data Structures and Algorithms with Object-Oriented Design Patterns in Java Reiss, A Practical Introduction to Software Design with C++ Schneider, Concurrent and Real-time Systems Winder & Roberts, Developing Java Software 2nd Edition The World of Scripting Lan uages David W. Barron University of Southampton, UK John Wiley & Sons, Ltd Chichester New York Weinheim Brisbane Singapore Toronto II II II II II Copyright © 2000 by John Wiley & Sons, Ltd Baffins Lane, Chichester, West Sussex P019 IUD, England National 01243779777 International (+44) 1243 779777 E-mail (for orders and customer service enquiries): [email protected] Visit our Home Page on http://www.wiley.co.uk or http://www.wiley.com Cover picture © ADAGP, Paris and DACS, London 2000 All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except under the terms of the Copyright, Designs and Patents Act 1988 or under the terms of a licence issued by the Copyright Licensing Agency, 90 Tottenham Court Road, London, UK WIP 9HE, without the permission in writing of the publisher, with the exception of any material supplied specifically for the purpose of being entered and executed on a computer system for exclusive use by the purchaser of the publication. Neither the author nor John Wiley & Sons, Ltd accept any responsibility or liability for loss or damage occasioned to any person or property through using the material, instructions, methods or ideas contained herein, or acting or refraining from acting as a result of such use. The author and publisher expressly disclaim all implied warranties, including merchantability or fitness for any particular purpose. There will be no duty on the author or publisher to correct any errors or defects in the software. Designations used by companies to distinguish their products are often claimed as trademarks. In all instances where John Wiley & Sons, Ltd is aware of a claim, the product names appear in initial capital or all capital letters. Readers, however, should contact the appropriate companies for more complete information regarding trademarks and registration. The author has exerted his moral right under the Copyright, Designs and Patents Act 1988 to be identified as the author of this work. Other Wiley Editorial Offices John Wiley & Sons, Inc., 605 Third Avenue, New York, NY 10158-0012, USA Weinheim • Brisbane • Singapore • Toronto Library of Congress Cataloglng-In-Publicatlon Data Barron, D. W. (David William), 1935- The world of scripting languages / David W. Barron. p. cm. (Worldwide series in computer science) Includes bibliographical references and index. ISBN 0~471-99886-9 (alk. paper) 1. Programming languages (Electronic computers) 2. CGI (Computer network protocol) 3. World Wide Web. 1. Title. II. Series. QA76.6-B3715 2000 99-089450 British Library Cataloguing in Publication Data ISBN 0-471-99886-9 Typeset in 9/12 Garamond by Mayhew Typesetting, Rhayader, Powys Printed and bound in Great Britain by Biddies Ltd, Guildford, Surrey This book is printed on acid-free paper responsibly manufactured from sustainable forestry, in which at least two trees are planted for each one used for paper production. Contents Preface .................................. . xi Acknowledgements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. xiii PART ONE THE BIG PICTURE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 Introduction to and scripting . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.1 and programs.. ............................... 3 1.2 Origins of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.3 Scripting today. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. ...... 5 1.4 Characteristics of scripting . . . . . . . .. ............. 5 1.5 Uses for scripting languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.6 Web scripting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 12 1.7 Java............................................. 13 1.8 The universe of scripting . . . . . . . . . . . . . . . . . . . 13 PART TWO LANGUAGES..................................... 15 2 the done in Perl . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 2.1 The Perl phenomenon. . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 2.2 Introducing Perl. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 2.3 Names and values in Perl. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 2.4 Variables and ass;igrlm,ent. . . . . . . .. . ................... . 28 2.5 Scalar ext)ressi()ns 29 2.6 Control structures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 2.7 Built-in functions ................................... . 36 2.8 Collections of data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 2.9 Working with arrays and lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 2.10 Working with hashes ................................ . 45 2.11 input and output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 2.12 Strings, patterns and regular expressions. . . . . . . . . . . . . . . . . . . . . 48 2.13 Subroutines. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 2.14 Scripts with arguments . . .. .......................... . 61 2.15 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 2.16 Reference: operators and precedence . . . . . . . . . . . . . . . . . . . . . . . 63 Contents 3 Advanced Perl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 64 3.1 Finer points of looping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 64 3.2 Finer points of subroutines . . . . . . . . . . ................... , 65 3.3 Using pack and unpack. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 68 3.4 Working with files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 69 3.5 Navigating the file system. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 74 3.6 Typeglobs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 76 3.7 eval............................................. 78 3.8 References......................................... 79 3.9 Data structures. . . . . . . .............................. , 86 3.10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 88 3.11 Libraries and modules. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 89 3.12 Objects........................................... 92 3.13 Objects and modules in action ........................... , 97 3.14 Tied variables ....................................... 100 3.15 Interfacing to the system ......................... 103 3.16 Creating 'Internet-aware' applications ....................... 109 3.17 'Dirty hands' Internet programming ......................... 112 3.18 Security issues ...................................... 116 4 l'cl .................................................. 118 4.1 The Tel phenomenon. ................................. 118 4.2 The Tel philosophy. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 4.3 Tel structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 4.4 Tel syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 4.5 Understanding Tel: the parser . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 4.6 Variables and data in Tel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 4.7 Control flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 4.8 Data structures ...................................... 127 4.9 Simple input/output ................................... 130 4.10 Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 4.11 Working with strings .................................. 135 4.12 Working with patterns ................................. 136 4.13 Working with files and pipes ............................. 140 4.14 Putting it all together: some code .................... 142 4.15 Reference material. ................................... 144 5 Advanced Tel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148 5.1 The source, exec and uplevel commands ................. 148 5.2 Libraries and ................................. 149 5.3 Namespaces........................................ 152 5.4 Trapping errors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 155 5 .5 Event-driven programs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 5.6 Making applications 'Internet-aware' . . . . . . . . . . . . . . . . . . . . . . . . 159 5.7 'Nuts-and-bolts' Internet programming ....................... 161 Contents 5.8 <,:",,,,,,,,,,,,,,, issues: ... , ....... i..-"-. untmsted code. . . . . . . . . . . . . . . . . . . . .. 166 5.9 The C interface 169 5.10 The Java interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 173 6 Th .................................................. 176 6.1 Visual toolkits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 176 6.2 Fundamental concepts of Tk. . . . . . . . . . . . . . . . . . . . . . . . . . . .. 177 6.3 Tk by . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 182 6.4 Events and . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 198 6.5 Geometry managers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . " 202 6.6 Perl-Tk............... ........................... 207 7 Visual Basic and VBA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 210 7.1 The Visual Basic family . . . . . . . . . . . . . . . . . . . . . . . . 210 7.2 Visual Basic: the core . . . . . . . . .. ................ 213 7.3 The Visual Basic way of objects . . . . . . . . . . .. ............. 230 7.4 Object models and type libraries . . . . . . . . . . . . . . . . . . . . . . . . .. 231 7.5 \Ylr,. .. lri1"ln with . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 232 7.6 ...................................... 241 7.7 Event-driven programming. . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 245 7.8 Working with Visual Basic (the application). . . . . . . . . . . . . . . . . .. 247 7.9 Reference: operators and operator . . . . . . . . . . . . .. 255 8 Advanced Visual Basic. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 8.1 Opveloninp Internet-aware applications ..................... . 257 8.2 COM objects. . . . . . . . . . . . . . . . . . .. . ................ . 262 8.3 The Visual Basic event model. . . . . . . . . . . . . . . . . . . . . . . . . . . . 264 8.4 Class modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267 8.5 276 8.6 ActiveX controls. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 285 8.7 Intc::tl<ilCirlg to the Windows API. . . . . . . . . . . . . . . . . . . . . . . . . .. 286 8.8 AC(:essiing external databases. . . . . . . . . . . . . . . . . . . . . . . . . . . .. 288 PART THREE SCRIPTING WEB CLIENTS AND SERVERS . . . . . . . . . . . . . . . .. 293 9 295 9.1 What is ................................... 295 9.2 Object models. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 296 9.3 philosophy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 297 9.4 297 9.5 ............................ 298 9.6 objects. . . . . . . . .. ........................... 313 9.7 Advanced facilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 322 9.8 JavaScript and Java. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 324 9.9 If}u''1~f"''rint operators and pn~Cedel[1Ce 325 Contents 10 VBScript .............................................. 326 10.1 What is VB Script? .................................... 326 10.2 The VBScript core language ............................. 327 10.3 Objects in VBScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335 10.4 New features in VBScript 5 .............................. 338 11 Scripting Web clients and servers .............................. 344 11.1 Client-side Web scripting ............................... 344 11.2 Active Server Pages ................................... 362 12 Dynamic HTML and the DOM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368 12.1 From HTML to Dynamic HTML ........................... 368 12.2 Dynamic HTML ..................................... 369 12.3 Document object models ............................... 369 12.4 The Netscape document object model ....................... 370 12.5 The Microsoft document object model. . . . . . . . . . . . . . . . . . . . . . . 375 12.6 The W3C document object model (DOM) .................... 380 12.7 The event model. .................................... 381 12.8 DHTML scriptlets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391 PART FOUR THE MICROSOFT SCRIPTING MODEL 395 13 Scripting Microsoft Office . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397 13.1 VBA............................................. 397 13.2 Macros and macro languages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398 13.3 WordBasic......................................... 399 13.4 The Office object models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401 13.5 Programming the Word object model ....................... 404 13.6 Modifying Word's built-in dialogs. . . . . . . . . . . . . . . . . . . . . . . . . . 415 13.7 Events ........................................... 415 13.8 Automation: programming the Office suite .................... 418 13.9 Using the Windows API ................................ 422 13.10 Macro viruses ....................................... 423 14 The Microsoft Scripting Runtime Library. . . . . . . . . . . . . . . . . . . . . . . . . . 425 14.1 Scripting hosts, scripting and object libraries ............. 425 14.2 The Scripting Runtime Library ............................ 426 14.3 The Dictionary object. ................................. 426 14.4 The File System Object Model ............................ 428 14.5 Working with the FileSystemObject object .................... 430 14.6 The Drive object. .................................... 432 14.7 The File and Folder objects .............................. 433 14.8 Text I/O with the TextStream object ........................ 435 Contents 15 The Windows Script Host and the Script Control. . . . . . . . . . . . . . . . . . .. 440 15.1 What is the Windows Script Host? . . . . . . . . . . . . . . . . . . . . . . . .. 440 15.2 The Windows Script Host object model. . . . . . . . . . . . . . . . . . . . .. 441 15.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 444 15.4 The future of the Windows Script Host. . . . . . . . . . . . . . . . . . . . .. 446 15.5 The Script Control . . . . . . . . . . . . . . . . . .. ............... 446 PART FIVE AND FINALLY. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 449 16 Loose ends . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451 16.1 Pre-history of sCripting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 451 16.2 Precursors of scripting. . . . . . . . . . . . . .. ............ 452 AWK ............................................ 459 16.4 REXX....................... .................... 464 17 t;;pUo~!ue ............................................. . 474 Appendix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 477 Index ................................................... 485 Scripting Program Index. . . . . . . . . . . . . . . . . . . . . . . . .. ............ 490

Description:
Programming Languages/Web Programming The World of Scripting Languages David Barron The explosive growth of Internet applications has seen a corresponding growth in the use and development of scripting languages. Their power and flexibility enables even nonexpert programmers to prototype graphical u
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.