Perl comes with a whole bunch of cryptically-named built-invariables, which clever Perl programmers exploit to reduce the number oflines of code in their scripts. This article examines some of the morecommonly-used special variable in Perl, with examples and illustrations ofhow they may be used.
You may find this hard to believe, but the Practical Extraction and Reporting Language, affectionately referred to as Perl by thousands of developers worldwide, was born primarily because its creator needed a tool to generate reports from raw text data. Over the years, though, Perl has grown from strength to strength; today, while it still boasts a very complete (and very impressive) text manipulation API, it can also be used to talk to databases, parse XML, execute SSL transactions and perform a wide variety of other (arcane?) functions.
Now, for newbie Perl programmers, one of the chief obstacles they have to overcome is the somewhat hard-to-understand shorthand used by experienced developers. This shorthand usually takes the form of built-in variables - my personal favourite is @_ though at one time I remember a particular fondness for $? - which have special meaning to the Perl interpreter and which, correctly used, can save you quite a few lines of code in your Perl program. Here, then, is a guide to the more interesting and commonly-used special variables in Perl, together with examples that demonstrate how they may be used.