Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: begin with perl

by CountZero (Bishop)
on Oct 30, 2011 at 10:49 UTC ( [id://934697]=note: print w/replies, xml ) Need Help??


in reply to begin with perl

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

Replies are listed 'Best First'.
Re^2: begin with perl
by sad723 (Novice) on Oct 30, 2011 at 12:45 UTC

    when i test your code

    use Modern::Perl; say 'listes associatives'; my %url = ( fd => "www.forumdz.com", ok => "www.ouedkniss.com", se => "www.sec4ever.com" );

    i get this error with cygwin :

    sad723@sad723-PC ~/perl $ ./hash.pl ./hash.pl: ./hash.pl: cannot execute binary file

    and this error when i use cmd;

    C:\Perl\bin>hash.pl Unrecognized character \xE3 at C:\Perl\bin\hash.pl line 2.

      Unicode character \xE3 is 'Latin small letter a with tilde'.

      When I run your posted code, I don't get any error message. Are you sure there's no tilde on the 'a' in 'listes associatives' in your original?

        normally i'm sur no tild can't understand !!!!!!??,
      What Perl are you using?

      I have tried it on Strawberry Perl 5, version 12, subversion 1 (v5.12.1) and I have saved my script as ASCII, UTF-8, UTF-16 (both Big-endian and Little-endian), with and without a BOM (Byte Order Mark) and it all works without error.

      Perhaps there is something wrong with your set-up.

      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

        i use ActivePerl 5.8.3.809

        in cygwin i don't know the version

        ;

        i have three exemple of script perl;

        the two first scrip work good but the third on no

        confused !!!!!!!!!!!!!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://934697]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-20 02:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found