On Sun, 1 Jul 2001 [EMAIL PROTECTED] wrote:

> mr. cozens seems to have been speaking directly to me when he wrote 'one
> thing novice programmers want to do is construct a variable whose name is
> generated from the contents of another variable.'

These are known as symbolic references in Perl and are generally scorned
nowadays, since we have real references available.

> cozens recommends using a hash. this would be my first attempt at an
> associated array, and i am a bit confused at where to draw the lines on
> this one. since my problem is really just creating multiple arrays with
> unique names.

I would use a hash also -- a hash of anonymous arrays, indexed by a key in
the hash.  You don't have to create arrays with unique names then -- your
hash keys are the array names.  If you think of a hash being like an
array, but indexed with strings rather than with numbers, it makes it a
bit easier.  The value of a hash can easily be made into a reference to an
array, or even to another hash.

> $groupfile = "/etc/group";
> $passfile = "/etc/shadow";
>
> @domains = qw(foo.bar foa.bar fob.bar);

Create a hash here also:

my %domain_info;

> for $one(@domains) {
>   open FH, $groupfile or die $!;
>   while (<FH>) {
>      @group = split /:/, $_;
>     if ( $one eq $group[0] ) {
>        @$one = split /,/, $group[3];

This is definitely going to give you trouble here.  How about instead:

        $domain_info{$one} = \@{ split /,/, $group[3] }; #ref to an array

>     }
>   }
>   close FH;
>   open FH, $passfile or die $!;
>   open NH, ">/etc/htsec/$one.ht" or die $!;
>   while (<FH>) {
>     $line = $_;
>     @entry = split /:/, $line;
>     for $each(@$one) {

And here:
        for $each ( @{ $domain_info{$one} } )

>       chomp $each;
>       if ( $each eq $entry[0] ) {
>         print NH $line;
>       }
>     }
>   }
>   close NH;
>   close FH;

-- Brett

                                   http://www.chapelperilous.net/btfwk/
------------------------------------------------------------------------
Life is a sexually transmitted disease with 100% mortality.

Reply via email to