Loginskip to content

November 2nd, 2006

do so with a reference to a hash

#!/usr/local/bin/perl use myconsts qw(PI E); print “PI*E = “, PI * E, “n”; % mytest PI*E = 8.53973421775655 That’s worth a Perl of Wisdom: Put common sets of constants in their own modules using the Exporter, and use the modules where needed. If you prefer to use EQUIVALENCE well, it’s time to break the habit. You can create aliases for the same variable in Perl, but it’s rarely useful. The Aliasmodule provides an easy way of doing this if you must. If you want to alias one variable to the storage space of many, or vice-versa, as you can with EQUIVALENCE, well, you can’t. And you’ll get no sympathy from us. If you are a FORTRAN programmer who never uses, nor intends to use, EQUIVALENCE statements or COMMONblocks, good! God only knows the measure of misery and heartache that has been inflicted on humanity by these monstrosities. 12.4 Tips for the Shell Programmer You and the C programmer are Perl’s favorite children (assuming that by “shell” we are talking about the Unix variety; the DOS/NT command line interface is quite a different beast). You alone among the other newcomers think it’s quite natural for scalar variables to start with $, and you just need to get used to the fact that the $ is there during assignment as well as during reference. It may have seemed stifling at first that calls to external programs had to be wrapped in system(), although you were right at home with the use of backticks (“) to capture program output. But if you tried to compensate by using Shell.pm just to avoid those system() calls, try doing without. A shell script needs a low syntactical overhead for calling external programs because it can do so little itself; Perl can do so much that calls to other programs are much less frequent. Overcome the tendency to call those beloved programs like cut, head, sed, and yes, even awk for text filtering; once you’ve learned to do the same things in Perl, you will seldom feel the need to go back. If you try converting a shell script to Perl, you’ll find this principle rearing its head as you repeatedly excise calls to utility programs. A shell program is interpreted a line at a time, which means that you can have any old junk representing your thoughts to date on the future direction of your script, as long as it won’t actually get as far as executing any of those statements. Perl requires that the whole script be syntactically correct before it tries executing any of it, which means that you can’t even hide something in an if(0){ }block without making sure that it is syntactically correct. But you can achieve the effect you want by inserting a line consisting solely of __END__

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.