Hash ed array

Una raccolta di metodi pratici per lavorare su array ed hash in PERL.

Hash ed array

Stampare un hash

@keys = keys(%myhash);
foreach $k (@keys) {
        print "<li>The key '$k' has value '".$myhash{$k}."'";
}

Stampare array di hash

@keys = keys(%{@hashes[1]});
print join("<li>",@keys);
foreach $k (@keys) {
        print "<li>The key $k has value ".$hashes[1]{$k};
}

Inizializzare hash di array di hash

%component_tree = (
     component1 => [
         {name => "command1", id=> "001"},
         {name => "command2", id=> "002"},
         {name => "command3", id=> "003"},
         {name => "command4", id=> "004"}
     ],
 
     component2 => [
         {name => "command5", id=> "011"},
         {name => "command6", id=> "012"},
         {name => "command7", id=> "013"},
         {name => "command8", id=> "014"}
     ]
);

Inizializzare hash di hash

%component_tree = (
	component1 => {
		name	=> "command1",
		id	=> "001"
 	},
	component2 => {
		name	=> "command1",
		id	=> "001"
	}
);

Publication details

Category: Perl

Published by: loryzz on date: 06.01.2008 21:24:01

Last edit by: loryzz on date: 21.01.2009 11:28:35

Statistics

Details  This article has been viewed 3.189 times.

Send to

add to digg add to reddit add to furl add to facebook add to delicious add to google add to stumbleupon add to technorati add to ask add to live

Ratings

  • Currently 0; ?>/ TOTALSTARS
  • 1
  • 2
  • 3
  • 4
  • 5

Comments

Details 0 user comments, 0 still waiting.

Leave a comment

All comments must be approved by site administrator.
Please write comments on topic. Spam will be never approved.


Confirmation code

Please take a look to image and insert character into the form field.

Perl: Linked articles