Loading ...
Sorry, an error occurred while loading the content.
 

RE: [PBML] Query on arrays whose name is in a variable

Expand Messages
  • Sreeram B S
    Hi, Thanks Charles for the solution. It worked fine!! Regards, Sreeram Charles K. Clarkson wrote: ... A safe method is to use a hash
    Message 1 of 4 , Jun 24, 2005
      Hi,

      Thanks Charles for the solution. It worked fine!!

      Regards,
      Sreeram


      "Charles K. Clarkson" <cclarkson@...> wrote:
      Sreeram B S <> wrote:
      : HI,
      : I have one query about accessing the elements of an array whose
      : name is held in another variable.


      A safe method is to use a hash of arrays for the lists of books
      and animals. 'Perldsc' has details on data structures.


      use strict;
      use warnings;

      my @names = qw/ animal book /;
      my %lists = (
      animal => [ qw/ Tiger Lion Elephant / ],
      book => [ qw/ Text Note / ],
      );

      foreach my $name ( @names ) {
      print "Type = $name\n";
      foreach my $member ( @{ $lists{$name} } ) {
      print "\tWord = $member\n";
      }
      }

      HTH,

      Charles K. Clarkson
      --
      Mobile Homes Specialist
      254 968-8328



      Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html



      ---------------------------------
      Yahoo! Groups Links

      To visit your group on the web, go to:
      http://groups.yahoo.com/group/perl-beginner/

      To unsubscribe from this group, send an email to:
      perl-beginner-unsubscribe@yahoogroups.com

      Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.


      __________________________________________________
      Do You Yahoo!?
      Tired of spam? Yahoo! Mail has the best spam protection around
      http://mail.yahoo.com

      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.