Changed it to:

#!/usr/bin/perl
use warnings;
use strict;

my @english = qw(january february march april may june july);
my @french = qw(janvier fverier mars avril mai juin juily);
my %months;

$months{english} = \...@english;
$months{french} = \...@french;

for (keys %months) {
print "Months in $_ : @{$months{$_}} \n";
}

and it worked fine.

Thanks Uri.

Thanks
Jatin

On 9/3/2010 10:47 AM, Uri Guttman wrote:
"JD" == Jatin Davey<jasho...@cisco.com>  writes:
   JD>  #!/usr/bin/perl
   JD>  use warnings;
   JD>  use strict;

very good to see those.

   JD>  my @english = qw(january february march april may june july);
   JD>  my @french = qw(janvier fverier mars avril mai juin juily);

   JD>  my %months;
   JD>  my $eng_ref;
   JD>  my $fre_ref;

   JD>  $eng_ref = \...@english;
   JD>  $fre_ref = \...@french;

no need for that. you can assign the refs directly into the hash.

   JD>  $months{english} = $eng_ref;
   JD>  $months{french} = $fre_ref;

   JD>  for (keys %months) {

that is assigning each key to $_. you never use $_. so this will loop
TWO times as there are two keys.

   JD>  print "Months in english : @{$months{english}} \n";
   JD>  print "Months in french : @{$months{french}} \n";

so both lines get printed twice.

what you want is more likely this:

        foreach my $month (keys %months) {

                print "Months in $month : @{$months{$month}}\n";
        }

uri


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to