#!/usr/bin/perl use strict; use warnings; use Benchmark qw(:all); my %h; @h{'A'..'Z','a'..'z'} = 1..52; sub verbose { my $hash = shift; foreach my $key (sort keys %$hash) { print "$key: $hash->{$key}\n"; } } sub idiom { my $hash = shift; print map "$_: $hash->{$_}\n", sort keys %$hash; } timethese(100000, { 'Verbose' => 'verbose(\%h)', 'Idiom' => 'idiom(\%h)', }); timethese(1000000, { 'Verbose' => 'verbose(\%h)', 'Idiom' => 'idiom(\%h)', }); timethese(10000000, { 'Verbose' => 'verbose(\%h)', 'Idiom' => 'idiom(\%h)', });