On Mon, Jul 21, 2003 at 02:38:20PM -0700, Andrew Hurst wrote:
> At 01:22 PM 7/21/2003 -0800, Dennis Stout wrote:
> >> >"Dennis Stout"  wrote ...
> >> >         my %user_list = get_users($where);
> >> >
> >> >         foreach (keys %user_list) {
> >> >                 my $user = $_;
> >> >                 foreach (@{$user_list{$user}{DOMAIN}}) {
> >> >                         $user_list{$user}{DOMAINS} .=
> >> >"$user_list{$user}{DOMAIN}[$_],";
> >> >                 }
> >> >                 chop($user_list{$user}{DOMAINS});
> >> >...
> >>
> >> >$user_list{$user}{DOMAINS} .= "$user_list{$user}{DOMAIN}[$_],";
> >>
> >> That line is the culprit.  $_ contains each domain name as a text
> >> string.  Which evaluates to 0 when used as an integer, which then gives 
> >the
> >> first entry in the array.  Thus you get the first entry in the array as
> >> many times as you have entries in the array.  Try changing that to a
> >> regular (indexed) for loop and that should fix it.
> >
> >Good eye, I was too busy thinking of hashes and things.
> >
> >I hate array's.
> >
> >Should just be $user_list{$user}{DOMAINS} .= "$_,"; huh?
> 
> Yep.  After I sent the last email I realized that suggesting an indexed
> for loop was more effort than just deleting part of the string already
> there, like you just suggested.

This would be a good place for a join (perldoc -f join):

    $user_list{$user}{DOMAINS} = join ',', @{$user_list{$user}{DOMAIN}};

which lets you do away with the trailing chop() as well.

Since this has nothing to do with mod_perl, if you must reply, please
do it off-list.

Eric

Reply via email to