Loginskip to content

November 2nd, 2006

You need to make certain adjustments when coming

… return $fighter; } which would make your heart leap into your mouth in C, relax. In C terms, $fighteris being allocated from the heap, not from the stack, so it doesn’t become vulnerable as soon as the stack frame for make_warrior is unwound. Furthermore, the space allocated to $fighter doesn’t get freed as long as there is a reference to it, and $soldieris such a reference. As long as something needs the space, it remains allocated, and as soon as nothing needs it, it gets freed. This is what you’re used to spending all that time agonizing about in C. Functions don’t need ()after them if you have no arguments to supply them, but if you do this with functions of your own, then their definition (or a prototype declaration) should precede their use. Although in C the expressions a[i]and i[a] are equivalent, the corresponding expressions in Perl are not. If you find this surprising, you may need more help than we can provide. While Perl inherits many operators (and their precedence) from C and probably strives hardest to be accessible to the C programmer, it also strives to be as orthogonal as possible. For example, while Perl provides the same &&and || operators as C, they return their inputs instead of a Boolean value. In other words, $a||$bis $aif $a is true; otherwise it is $b. (The operators short-circuit the same way). In another example, Perl figures anything that could be an lvalue, should be, so a term containing the trinary (?:) operator is an lvalue if its left and right parts are lvalues. The substrfunction is an lvalue if the result of its first argument is modifiable. And as of version 5.6.0, you can even (in an experimental feature) create a function of your own that is an lvalue. Although no switch statement exists in Perl, this hasn’t stopped people from inventing several dozen ways of simulating one, the latest being Switch.pm, a module presented by Damian Conway at the fourth annual Perl Conference (http://conference.perl.com/). The reason there isn’t a switch is that when you start implementing one, your average switch statement seems very limited when you consider the breadth of Perl’s operators. Why should each case be just a simple test for equality? Why not be able to compare against a regular expression as well? (Even the Bourne shell manages that.) Why shut out the vast set of logical comparisons? Until Switch.pm, it appeared that nothing could be implemented that wouldn’t look like a poor cousin to the rest of the language. (It now seems that some version of Switch.pm will be incorporated into the core Perl 6 language.) Hierarchical data structures are thoroughly typeless (atypical?) in Perl; no more fiddling with union statements to traverse heterogeneous lists. Sometimes, people are afraid this means that they must pedantically check the type of every element of a complex object themselves to make sure they don’t dereference something incorrectly; that is, until they realize that they were probably the ones who constructed the object in the first place, and they can usually trust themselves. Don’t look for a counterpart to struct expecting that you’ll use it nearly as much. If you want to achieve exactly the same effect (named members of a compound variable) you can

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

Comments are closed.