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. 12.2 Tips for the C Programmer You no longer must declare all your variables at the beginning of a block before any executable code. In fact, declaring them as late as possible is good practice because it keeps statements that belong to the same functional element together. Perl’s scalar variables are not strongly typed. They can switch oyster-like between integers, floating point numbers, and strings according to your whim (although if you ever turn a reference into a string, you can’t turn it back). Even when you assign an object of a specific class to one, nothing stops you from overwriting it with an object of another class or something that isn’t even an object at all. Polymorphism at its best. There is (as of version 5.005) the capability to declare to the compiler that a scalar is an object belonging to a particular class (myDog$spot), but even that is only a loose agreement that you can break any time you feel like it.[2] (It allows for compile-time checking of accesses to fields, which are one way of implementing instance data.) [2] As of press time, Damian Conway had mooted a module which could restrict a variable to a particular object class, but not even the name had been agreed on. Dynamic (i.e., nonlexical) variables have global scope unless qualified with a local statement. But you won’t want to program in this BASIC style anyway; declare all variables as lexical, and the scoping rules are the same ones you’re already used to. Your days of wondering whether your frees match your mallocs are over! It is very hard to create a memory leak accidentally in Perl. Whenever you see code like this $soldier = make_warrior (’squaddie’); sub make_warrior { my $fighter;
Hint: If you are looking for very good and affordable webspace to host and run your j2ee hosting application check Virtualwebstudio j2ee web hosting services