elavazhagan perl wrote:
> 
> Please have a glance on the following code and suggest me to purify it.....
> My requirement is when the user choose the region,I need to display the
> countries specific to that regions.
> I have been trying in both hash and array references.This one is for
> arrayref.
> 
> I have already the values of $RegionStmt in an individual array...
> I hope that we can use the following statement to retrive the first value of
> the first array ref.  $countryValues= $Regions[0][0];
> I would like to retrive all the values instead of single one.....Please
> suggest me.
> 
> Thanks  .
> 
> #Start
> #! /usr/local/perl/bin
> use strict;
> 
> my @Regions = (
> 
> 
> ["Belgium","Denmark","France","Germany","GreatBritain","Hungary","Portugal","Russia","Spain","Sweden","Turkey"
> ],
> 
> 
>        [ "Australia","China","India"," Malaysia"," New Zealand","
> Philippines"," South Africa"," Taiwan"," Vietnam" ],
>        [ "U.S."," Canada"," Mexico" ],
>        [ "Argentina"," Brazil"," Venezuela" ],
>     );
> 
> 
> 
>  foreach my $RegionStmt (@Regions) {
> 
>     if ($RegionStmt =~ /Europe/)
> {
> 
> $countryValues= $Regions[0];
> print "countryValues: $countryValues<br>\n";
> 
> }
> elsif ($RegionStmt =~ /Asia/)
> {
> 
> $countryValues = $Regions[1];
> }
>  elsif ($RegionStmt =~ /North/)
> {
> 
> $countryValues = $Regions[2];
> }
> 
> elsif ($RegionStmt =~ /South/)
> {
> 
> $countryValues=  $Regions[3];
> }
> 
> }

Your loop sets the value of $RegionStmt to each of the four array references in
@Regions. Nothing in your code has the values 'Asia', 'Europe' etc. to match the
regular expressions you're using.

I suggest you need a hash like this, but how you use it depends on your 
application.

HTH,

Rob


my %Regions = (
  Europe => [
    'Belgium',
    'Denmark',
    'France',
    'Germany',
    'Great Britain',
    'Hungary',
    'Portugal',
    'Russia',
    'Spain',
    'Sweden',
    'Turkey',
  ],
  Asia => [
    'Australia',
    'China',
    'India',
    'Malaysia',
    'NewZealand',
    'Philippines',
    'South Africa',
    'Taiwan',
    'Vietnam',
  ],
  North => [
    'U.S.',
    'Canada',
    'Mexico',
  ],

  South => [
    'Argentina',
    'Brazil',
    'Venezuela',
  ],
);

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to