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:

use strict; use warnings;
or, if you use a recent version of Perl:
use Modern::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:

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"; }
If you wish to extract both keys AND values in one operation, you use the each keyword in a while-loop.
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


In reply to Re: begin with perl by CountZero
in thread begin with perl by sad723

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.