Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


January 1998

Perl Basics


RSS
Subscribe to Windows IT Pro | See More Registry Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!
Main Article    Modify the Registry with Perl

Here are a few fundamentals of Perl that you'll want to keep in mind as you examine the WINSer.pl script. Perl's key variable types are scalar, array, and hash. A special character in front of the variable name identifies each type. Table A summarizes the main ideas about Perl's variable types.

As you work with Perl, keep in mind that it is case sensitive (i.e., it treats uppercase and lowercase characters as different characters). Thus, Perl recognizes $primary and $Primary as different variables. Perl is also a weakly typed language, which means that you don't need to declare a variable before using it. You can introduce variables anywhere in a Perl script.

Larry Wall, the author of Perl, has studied linguistics extensively. As a result, Perl has many natural language features. As you study Perl, you'll discover that Perl offers alternative ways to say the same thing, and provides many contractions that simplify expressing common actions.

Perlisms in WINSer.pl
Perl strings come in many flavors, the most common of which are single-quoted and double-quoted strings. Perl interpolates double-quoted strings, which means that Perl will substitute for escape sequences and other variables in the string. For example, if the third item in the @pets array is "camel", the line

print "Larry's favorite pet is his $pets[2].\n";

prints the following string on the display: Larry's favorite pet is his camel.

Perl supports short-circuit evaluation of Boolean operators. For example, when asked to evaluate A or B when A is true, Perl skips evaluating B because it doesn't need to evaluate B to verify the value of the expression. Thus, you will commonly see conditional statements such as

open(HANDLE, "<filename.txt") or die "Unable to open file filename.txt\n";

which means "open this file or die." Perl offers the more traditional || and && operators from C, as well as or and and. The advantage of or and and is that their precedence level is lower so they're less likely to cause problems if you forget to put parentheses around the two halves of the statement.

Perl has excellent support for regular expressions. Regular expressions are a method of expressing string pattern matches. For instance, the line

$boo =~ /^[A-Z][a-z]*$/;

tests whether $boo contains a capitalized word. The ^ symbol matches the start of the string, [A-Z] matches an uppercase character, [a-z]* matches zero or more lowercase characters, and $ matches the end of the string. For more information about regular expressions, consult the references in the online sidebar, "Perl Resources," at http://www.winntmag.com.

End of Article



Reader Comments
i thick much more details is necessary

Anonymous User February 21, 2005 (Article Rating: )


hjghg hggh

Anonymous User July 08, 2005 (Article Rating: )


You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Confirmed: Battery Life Issues Not Windows 7's Fault

Microsoft on Monday issued a lengthy statement about the recent Windows 7 battery controversy, echoing my assessment from earlier in the day, but backing it up with hard, cold evidence. ...

Battery Life Issues Almost Certainly Not Windows 7's Fault

While Microsoft is still investigating a notebook battery life issue that was supposedly caused by Windows 7, some interesting trends have emerged. ...

Microsoft Warns of Windows Version Expirations

Microsoft warned that this year will see three out-of-date Windows versions slip into retirement. ...


Task Automation Whitepapers Three Ways to Prevent Insider Risk within Your SCCM-Managed Environment

From Development to Production: Streamlining SharePoint Deployment with DocAve Deployment Manager

Related Events Deep Dive into Windows Server 2008 R2 presented by John Savill

Check out our list of Free Email Newsletters!

Task Automation eBooks Spam Fighting and Email Security for the 21st Century

A Guide to Windows Certification and Public Keys

Keeping Your Business Safe from Attack: Patch Management

Related Task Automation Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2010 Penton Media, Inc. Terms of Use | Privacy Statement