
Zhris
Enthusiast
Apr 24, 2014, 4:34 PM
Post #4 of 7
(17745 views)
|
Re: [Laurent_R] print numbers from 1 to 100 and a to z as index by using hashes
[In reply to]
|
Can't Post
|
|
Nice logic, it hadn't crossed my mind to shift off each letter and (re)build when empty. Might as well post my actual code with the OP's hash requirement in mind, although your solution is nicer:
my @nums = (1..100); my @lets = ('A'..'Z'); my %hash; @hash{@nums} = (@lets) x round_up(@nums/@lets); print "$hash{$_}:$_\n" for (sort { $a <=> $b } keys %hash); sub round_up { return int $_[0] == $_[0] ? $_[0] : int $_[0] + 1; } Chris
(This post was edited by Zhris on Apr 24, 2014, 4:39 PM)
|