good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: begin with perlby CountZero (Bishop) |
on Oct 30, 2011 at 10:49 UTC ( [id://934697]=note: print w/replies, xml ) | Need Help?? |
Bonjour et bienvenue dans notre Monastère! These are my comments on your little script. I gather you run this on some Windows version, so the first two lines are not really necessary. Windows applies another mechanism to link your script to the Perl interpreter. It is far better to replace these by the following: or, if you use a recent version of Perl: It has the same effect, but also activates some "modern" functions and commands, such as say. Please note that once you have activated the strict mode, you have to use lexical "my" variables throughout your script or you have to fully qualify your global variables. Next, the separator between the key and the value of your hash elements is not "=", but either a simple comma "," or the "fat comma" "=>". The fat comma automatically quotes your key value (provided it is only one word long). To get the values of your hash, you use the values keyword, to get the keys of the hash, you use the keys keyword. Applying the above, we get: If you wish to extract both keys AND values in one operation, you use the each keyword in a while-loop.
CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
In Section
Seekers of Perl Wisdom
|
|