You were heading in the right direction with your first for loop - but it got away from you (don't you just hate it when that happens?). Use strict and warnings _and_ don't comment them out. :-)
Read up on Perl data structures, what you needed was a hash of arrays. e.g. Data Types and Variables
Good luck!
produces#!/usr/bin/perl use warnings; use strict; my @country = ( "Australia", "south","Austria","America","India","Zimbabwe" ); # build a table - a hash of arrays (HoA) my %table; foreach my $country (@country) { my $init = uc substr($country,0,1); push @{$table{$init}}, $country; } # output the table for my $letter (sort keys %table){ print qq{$letter = }; for my $country (sort @{$table{$letter}}){ print qq{$country }; } print qq{\n}; }
updated: added linkA = America Australia Austria I = India S = south Z = Zimbabwe
In reply to Re: I ve an urgent issue..
by wfsp
in thread I ve an urgent issue..
by sara_perl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |