[ic] perl error setting scratch variable

Kevin Walsh interchange-users@interchange.redhat.com
Fri Apr 12 16:51:00 2002


> > >
> > > If anyone can look at this and tell me where the error is I would really
> > > appreciate it.
> > > Here is the code:
> > >
> > > [perl tables="userdb"]
> > >   @subscriptions = split(/\s+/, $Tag->data('userdb', 'mail_list',
> > > $Values->{mv_username});
> > >   foreach $my_item (@subscriptions) {
> > >     $Tag->set('subscriptions', $my_item . '=Y' );
> > >   }
> > > [/perl]
> > >
> > Change that set() thing to this:
> >
> >     $Scratch->{subscriptions} .= "$my_item=Y";
> >
> > ...that seems to be the intent of your code, but you will end
> > up with a string like this:
> >
> >     foo=Ybar=Yhello=Yworld=Y
> >
> > I said 'intent' because each iteration of your loop would
> > just overwrite the previous value and seems wrong to me.
> >
> > What is it that you're trying to do?
> 
> hrrmmm... no I was hoping that each iteration would create a new scratch
> variable.
> something similar to this:
> [set subscription]
> item_1=Y
> item_2=Y
> item_4=Y
> [/set]
>
That doesn't create a new scratch for each item.  That's a single
scratch containing several items separated using a new line.

To get that effect, you would put this in your loop:

    $Scratch->{subscription} .= "$my_item=Y\n";

> 
> I thought you used [set] to set scratch variables?
> 
You do, but if you are in a block of Perl code then you may as
well just set the scratch yourself, rather than call a subroutine
to do it for you.

>
> I guess to get what i want working i would want to do this then:
> 
> $Scratch->{$my_item} = 'Y'
> 
> for each iteration.
> 
That would set a scratch that could be referenced like [scratch item_1].
if that is what you need then your example is perfect.

-- 
   _/   _/  _/_/_/_/  _/    _/  _/_/_/  _/    _/
  _/_/_/   _/_/      _/    _/    _/    _/_/  _/   K e v i n   W a l s h
 _/ _/    _/          _/ _/     _/    _/  _/_/    kevin@cursor.biz
_/   _/  _/_/_/_/      _/    _/_/_/  _/    _/