Subscribe to Windows IT Pro

 

Get Newsletters

  • Get the Latest News
  • Product Updates
  • Helpful Tricks
  • Productivity Tips

Subscribe Now!

January 01, 1998 12:00 AM

Perl Basics

Windows IT Pro
InstantDoc ID #3457
Rating: (6)

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.

Related Content:

ARTICLE TOOLS

Comments
  • Anonymous User
    7 years ago
    Jul 08, 2005

    hjghg hggh

  • Anonymous User
    7 years ago
    Feb 21, 2005

    i thick much more details is necessary

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

White Papers

Get your Windows 7 deployment off to the right start by implementing PC lockdown. A locked-down environment is easier and cheaper to support since users are less likely to make unnecessary changes to the core system configuration - read more here!

Essential Guides

Is your iSCSI "lossy"? The reality is that most off-the-shelf Ethernet hardware deployed for iSCSI can lose packets, resulting in slow performance or application downtime. Learn how to assess your current iSCSI infrastructure and engineer an advanced iSCSI SAN infrastructure.

Web Seminars

What's the best way to keep your network safe from malware? In this web seminar, security expert Greg Shields suggests an alternative method to the traditional blacklisting approach that is common with anti-virus and anti-malware solutions.

eLearning Series

We bring the experts direct to you to share their real-world perspective and expertise. During each event, three sessions stream in real time, so you can learn, ask questions, and get solutions.
Upcoming event: Getting the Most with Exchange 2010 with Paul Robichaux

Subscribe to Windows IT Pro!

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.