in reply to begin with perl
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:use strict; use warnings;
It has the same effect, but also activates some "modern" functions and commands, such as say.use Modern::Perl;
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.use Modern::Perl; say 'listes associatives'; my %url = ( fd => "www.forumdz.com", ok => "www.ouedkniss.com", se => "www.sec4ever.com" ); #----------------------------- say 'liste des URL'; foreach my $val (values %url) { print "$val\t"; }
say 'liste des abbreviations et URL'; while (my ($key, $ val) = each %url) { print "$key: $val\t"; }
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: begin with perl
by sad723 (Novice) on Oct 30, 2011 at 12:45 UTC | |
by Not_a_Number (Prior) on Oct 30, 2011 at 13:27 UTC | |
by Anonymous Monk on Oct 30, 2011 at 14:02 UTC | |
by Not_a_Number (Prior) on Oct 30, 2011 at 14:31 UTC | |
by CountZero (Bishop) on Oct 31, 2011 at 07:04 UTC | |
by sad723 (Novice) on Nov 01, 2011 at 09:48 UTC | |
by sad723 (Novice) on Nov 01, 2011 at 10:50 UTC |