lecture d une table de hash a partir d un fichier

Creation: 18 mai 2013
Mise à jour:
Version: 1.0
Author: Jean-Louis Bicquelet-Salaün
Location: http://jlbicquelet.free.fr
Copyright: (c) 2013 Jean-Louis BICQUELET-SALAÜN
read_hash  

  hash table

 

06/01/2012  

read_hash

lit un fichier contenant un hashtable. Le format du fichier est

_______________
val1=1
val2=2
etc.
_______________
En sortie on affiche la table de hashage.
val1->1
val2->2

exemple:

# lecture du fichier
open(FILE,"hash.txt");
my %hash; 
while () {    
  chomp;    
  my ($key, $val) = split /=/;    
  $hash{$key} = $val;
}
close FILE;

# affichage du hash
my ($key,$val);
while (($key,$val)= each(%hash)) {
   print "$key->$val\n";
}