Scripting Central--More About How to Get Started Writing Scripts--July 7, 2006

Learn about some resources that you can use to learn how to write JScript, Perl, and T-SQL code. In addition, learn why UNIX administrators won't be laughing anymore and why VBScript enthusiasts no longer have to wish for an IIf function.

10 Min Read
ITPro Today logo in a gray background | ITPro Today

Perspectives

  • More About How to Get Started Writing Scripts

This & That

  • Hey, Congratulations Scripting Guys

Script Watch

  • UNIX Administrators Won't Be Laughing Anymore

Scripter's Toolkit

  • If I Only Had an IIf Function

Info To Go

Perspectives
by Karen Bemowski, [email protected]

More About How to Get Started Writing Scripts
If you read "How to Get Started Writing Scripts" (http://www.windowsitpro.com/Windows/Article/ArticleID/50486/50486.html) last month, you know about some resources that you can use to learn how to write Windows shell, VBScript, and Windows PowerShell code. As with chocolate and potato chips, getting just a taste of learning makes you hungry for more. So, I want to cover resources that you can use to learn how to write JScript, Perl, and T-SQL code.

JScript
Like VBScript, JScript is a scripting language associated with Windows Script Host (WSH), an environment for executing scripts. Consequently, you might expect to see some WSH references in a list of JScript resources. However, that's not the case. Most WSH resources don't include information about JScript. For example, Tim Hill's Windows Script Host (New Riders Publishing, 2003) is highly recommended for learning WSH and VBScript but doesn't include any information helpful in learning JScript. Surprisingly, even the Windows scripting bible--Windows 2000 Scripting Guide (Microsoft Press, 2003)--contains no information about JScript.

Fortunately, because JScript is Microsoft's implementation of JavaScript, you can use JavaScript resources to learn JScript. One of the scripting experts I talked with got his start with JScript by reading David Flanagan's JavaScript: The Definitive Guide (O'Reilly, 2001). This book provides a solid overview of the JavaScript language.

Another book that you might read is Michael Moncur's Sams Teach Yourself JavaScript in 24 Hours, 4th ed. (Sams Publishing, 2006). Note that I said "might"; the scripting experts I talked with aren't familiar with this book. On Amazon.com, it received an average rating of 3 stars out of a possible 5. In comparison, JavaScript: The Definitive Guide received a rating of 4.5 stars. Another resource for learning JScript is the JScript Fundamentals Web page at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/0441e1e5-34e4-4d32-b188-f7fc35613478.asp.

If you run into problems learning JScript, you can talk with fellow scripters at Windows IT Pro's Scripting forum (http://forums.windowsitpro.com). This forum covers all types of scripting languages, so it's a good Web site to bookmark in your browser.

Perl
Perl is one of the harder scripting languages to learn. However, it offers some benefits, such as being able to run your scripts not only on Windows platforms but also on other platforms, such as Linux and Macintosh. The "PERL: The Practical Extraction & Reporting Language" Web page at http://www.roth.net/perl discusses some other benefits of using Perl. This Web page also has a link to the ActiveState Web site, which offers a free, ready-to-install distribution of Perl called ActivePerl. One of the most popular Perl distributions, ActivePerl includes not only the core Perl engine but also some popular Perl modules and the Perl Package Manager (PPM) for installing Comprehensive Perl Archive Network (CPAN) modules.

If you're a Perl newbie, you might be wondering what modules are. Perl modules are reusable software components that offer specific functionality. For example, the Win32::Perms module lets you modify permissions on files, directories, registry keys, network shares, and shared printers. The only way you can take advantage of a Perl module's functionality is through a Perl script--you can't run modules by themselves. The CPAN Web site (http://www.cpan.org) offers a large collection of Perl modules. The PPM for CPAN lets you install a Perl module from that Web site by typing a simple command.

After you've installed ActivePerl or another Perl distribution, you're ready to learn Perl. The book to start with depends on your background:

  • If you aren't familiar with programming concepts and would like to use Perl on cross platforms, check out Learning Perl, 4th ed. (O'Reilly, 2005) by Randal L. Schwartz, Tom Phoenix, and Brian D. Foy.

  • If you're already familiar with programming concepts and would like to use Perl on cross platforms, check out Programming Perl, 3rd ed. (O'Reilly, 2000) by Larry Wall, Tom Christiansen, and Jon Orwant. This book is considered to be the Perl bible.

  • If you aren't familiar with programming concepts and would like to use Perl on the Win32 platform only, check out Learning Perl on Win32 Systems (O'Reilly, 1997) by Randal L. Schwartz, Erik Olson, and Tom Christiansen.

After you have a basic understanding of the Perl language, you can focus on areas of interest to you. For Windows systems administrators, two books of interest are

  • Dave Roth's Win32 Perl Programming: The Standard Extensions, 2nd ed. (New Riders, 2001). This book covers many of the standard Win32-specific modules that come with Perl.

  • Dave Roth's Win32 Perl Scripting: The Administrator's Handbook, 2nd ed. (New Riders, 2000). This book discusses how to use Perl to automate common tasks that Windows administrators face.

DBAs will want to check out Programming the Perl DBI (O'Reilly, 2000) by Alligator Descartes and Tim Bunce. This book covers the Perl Database Interface (DBI), a Perl-specific interface that provides database functionality.

If you run into problems learning Perl, I suggest visiting some of the many newsgroups and forums in which you can talk with Perl enthusiasts. Besides Windows IT Pro's Scripting forum, you can check out the forums and newsgroups listed on the Win32 Perl Links Web page at http://www.roth.net/perl/links.

T-SQL
T-SQL is the built-in scripting language of Microsoft SQL Server. T-SQL underwent some major changes in SQL Server 2005, so if you want to learn this scripting language, it's best to learn the 2005 version. One recently released book that might help you do so is Beginning Transact-SQL With SQL Server 2000 and 2005 (Wrox Press, 2005) by Paul Turley and Dan Wood. None of the scripting experts I talked with are familiar with this book, but it received an average rating of 4 stars on Amazon.com. Another resource is SQL Server 2005 Books Online (BOL). You can download this BOL for free at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx.

Because T-SQL is based on SQL, learning about SQL can be helpful. To get a background on SQL, you can check out Robert Sheldon's SQL: A Beginner's Guide, 2nd ed. (McGraw-Hill Osborne Media, 2003).

If you run into problems learning T-SQL, you can ask questions on SQL Server Magazine's T-SQL forum at http://sqlforums.windowsitpro.com. For a list of T-SQL newsgroups and Web sites, go to http://www.insidetsql.com/resources.htm.

This list of JScript, Perl, and T-SQL resources isn't all-inclusive. If you've come across any other helpful resources, please let me know and I'll add them to the list.

This & That

Hey, Congratulations Scripting Guys!
On July 21, Microsoft will publish the 500th "Hey, Scripting Guy!" article. To mark this monumental milestone, Microsoft is featuring a sweepstakes, a postcard contest, and daily comic scripts (don't expect to laugh too much, though). To join the celebration, go to the Microsoft Script Center (http://www.microsoft.com/technet/scriptcenter/default.mspx). By the way, if you ever wondered who the scripting guys really are, check out the Web page at http://www.microsoft.com/technet/scriptcenter/sgwho.mspx.

Script Watch

UNIX Administrators Won't Be Laughing Anymore
Windows scripting has long been the butt of jokes from UNIX system administrators mainly because Windows has been lacking many key features that make scripting truly useful. However, Microsoft is now not only catching up to but actually surpassing other OSs' scripting capabilities with its new Windows PowerShell scripting environment. Formerly code-named Monad, PowerShell delivers several scripting capabilities that Windows has never had and greatly improves some existing features. Learn how PowerShell is filling in the capability gaps in the article "Introducing Windows PowerShell," which will be featured in the August issue of Windows IT Pro.

Scripter's Toolkit

If I Only Had an IIf Function

VBScript enthusiasts no longer have to wish for an IIf function. Short for Immediate If, IIf is a simple but helpful function that's native to Visual Basic for Applications (VBA) but non-existent in VBScript. However, with some simple creative coding, you can create a VBScript function that has the same functionality.

The IIf function evaluates an expression and returns a specific value, depending on whether the expression evaluates to True or False. Thus, you can use the IIf function in place of VBScript's If...Then...Else statement.

The IIf function contains only three lines of code:

   Function IIf(expr, truepart, falsepart)      If expr Then IIf = truepart Else IIf = falsepart   End function

You place this function in your script, then call the function, following the syntax

   IIf(expr, truepart, falsepart)

where expr is the expression you want to evaluate, truepart is the value or expression returned if expr is True, and falsepart is the value or expression returned if expr is False. For example, the calling code might look like

   returnValue = IIf(A = B, "A equals B", "A is not equal to B")

If the value of what is stored in variable A equals the value of what's stored in variable B, then returnValue would contain the string "A equals B". Otherwise, returnValue would contain the string "A is not equal to B".

You can use just about any type of expression in the IIf function. Similarly, the function can return just about any type of value (e.g., character, number, date). The expressions in the argument list can include calls to other functions and nested IIf functions. You can even nest IIf within other VBScript functions.

Thanks to Jim Turner for writing and sharing his VBScript IIf function.

Info To Go

Save $80 Off the Windows Scripting Solutions Newsletter
Get endless scripting techniques and expert-reviewed code. Subscribe to Windows Scripting Solutions today and save $80:
https://store.pentontech.com/index.cfm?s=1&promocode=eu2667us

Discounted Offer for the Windows IT Pro Master CD
Save 50% off the Windows IT Pro Master CD! Order now and get portable, high-speed access to the entire Windows IT Pro article database on CD--a searchable library that includes every issue ever published. The newest issue also includes BONUS Windows IT Tips. Order now and save 50%:
https://store.pentontech.com/index.cfm?s=9&promocode=eu2267uc

Achieve compliance in today's complex regulatory environment while managing threats to the inward- and outward-bound communications vital to your business. Adopt a best-practices approach, such as the one outlined in the international information security standard ISO/IEC 17799:2005. Download the white paper today and secure the confidentiality, availability and integrity of your corporate information!
http://www.windowsitpro.com/go/whitepapers/surfcontrol/securitystandard/?code=0705featwp

Are you protected company-wide against spyware, keyloggers, adware, and backdoor Trojans? Test the state of the art scanning engine that uses threat signatures from multiple sources to track down the culprits that antivirus solutions alone can't protect you against. Download your free 30 day trial of CounterSpy Enterprise today!
http://www.windowsitpro.com/go/download/sunbelt/counterspy/?code=0705emailannc

Learn how a database utility for SQL Server can lower operational costs, simplify management, and increase the availability of your SQL Server deployment. Live event: Tuesday, June 20
http://www.sqlmag.com/go/seminar/polyserve/availability/?partnerref=0626emailannc

Take an up-to-date look at secure, remote access to corporate applications and stay ahead of the curve when making decisions about near- and long-term IT infrastructure. On-demand Web seminar.
http://www.windowsitpro.com/go/seminars/whale/vpn/?partnerref=0705emailannc

Gain control of your messaging data--and make your job easier--with these step-by-step instructions for complying with the law and ensuring your systems are working properly.
http://www.windowsitpro.com/toolkits/ilumin/index.cfm?code=0705emailannc

Learn how to gather evidence of compliance across multiple systems and link the data to regulatory and framework control objectives. View this on-demand Web seminar today!
http://www.windowsitpro.com/go/seminars/bindview/multiregcompliance/?partnerref=0705emailannc

Contact Us

This email newsletter is brought to you by Windows IT Pro, the leading publication for IT professionals deploying Windows and related technologies. Subscribe today!
https://store.pentontech.com/index.cfm?s=1&promocode=eu205xfb

View the Windows IT Pro Privacy Policy.
http://www.winnetmag.com/aboutus/index.cfm?action=privacy

Windows IT Pro is a division of Penton Media, Inc. 221 East 29th Street, Loveland, CO 80538, Attention: Customer Service Department

Copyright 2006, Penton Media, Inc. All Rights Reserved.

Read more about:

ITPro Today
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like