Luinrandir <mailto:[EMAIL PROTECTED]> wrote:
: OK.. maybe I'm trying to be too fancy.
:
: the package is:
: ###################
: package Names;
: @Countries("Ireland","Wales");
: %Lord{Ireland}=("Bob","Tom");
: %Lord{Wales}=("Ted","Ned");
:
: return 1;
: #################
: the program is:
: ###################
: foreach $Country(@Names::Countries)
: {
:     print qq|$Names::$Lord{$Country}|;
: }
: ###################
:
: I have tried several variation on this.. can't get it to work.
: I need it to print the array of Ireland and then Wales.

    And later:

: my alternative is this, in the program:
:
:    @[EMAIL PROTECTED]::Countries;

    I assume that should be Names and not NamesList.


package Names;

%Lords = (
    Wales   => [ qw( Ted Ned ) ],
    Ireland => [ qw( Bob Tom ) ],
);


use Names;

{
    # Use a shorter name to access %Names::Lord
    my $lords = \%Names::Lords;

    foreach my $Country ( qw( Wales Ireland ) ) {

        print "@{ $lords->{ $Country } }\n"
                            if exists $lords->{ $Country };
    }
}

__END__


    If you don't know the country names ahead of time
you can use the keys from %Names::Lord. @Names::Countries
array is not necessary.

use Names;

{
    # Use a shorter name to access %Names::Lord
    my $lords = \%Names::Lords;

    foreach my $country ( keys %$lords ) {

        print "@{ $lords->{ $country } }\n";
    }
}


HTH,

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


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


Reply via email to