CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: I need a program that...: Re: [vikasmetla] print numbers from 1 to 100 and a to z as index by using hashes: Edit Log



BillKSmith
Veteran

Apr 24, 2014, 9:46 PM


Views: 17252
Re: [vikasmetla] print numbers from 1 to 100 and a to z as index by using hashes

You problem is more easily done with an array. If a hash is reqired, use a hash with integer keys to simulate the array.

Code
use strict; 
use warnings;
my @array = ('a' .. 'z');
for (1..100){
my $i = (($_-1) % 26);
print "$array[$i]:$_\n"
}

my %hash;
@hash{0..25} = 'a' .. 'z';
for (1..100){
my $i = (($_-1) % 26);
print "$hash{$i}:$_\n"
}


UPDATE: Changed hash initialization to use OP's hash sclice.
Good Luck,
Bill

(This post was edited by BillKSmith on Apr 25, 2014, 7:35 AM)


Edit Log:
Post edited by BillKSmith (Veteran) on Apr 25, 2014, 7:35 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives