12.1. Tips for Everyman

You need to make certain adjustments when coming to Perl from more familiar languages:

  • Variables begin with type-specifying punctuation characters[1] referred to by some as sigils. It's not quite the revenge of Hungarian notation—no mblock *apmblkMessages[] here, thank goodness. The hardest thing for a Perl beginner to assimilate is that while, for example, @animals is the name of an array, $animals[14] is the name of a particular element in it, and @animals[2..7] is the name of a slice of that array. Just remember the rule that when you're referring to exactly one thing, it's a scalar and therefore begins with a $, whereas multiple things are an array—sort of—and begin with an @ sign.

    [1] Well, most of them. Filehandles don't, unless you create one in a scalar with IO::FileHandle or the new 5.6 feature or assign a typeglob alias. And you'd have a hard time telling the difference between an lvaluable subroutine and a variable.

  • Function arguments don't have to be surrounded by parentheses. Putting them in won't hurt, but knowing when you can leave them out makes your program easier to read. (See “The Case of the Vanishing Parentheses” in Chapter 4.)

  • Because Perl insists on conditional clauses being blocks, there is no “dangling else” problem.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset