[ic] perl error setting scratch variable

interchange-users@interchange.redhat.com interchange-users@interchange.redhat.com
Fri Apr 12 17:37:01 2002


> From:  Kevin Walsh
>
> >
> > 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.

That's helpful to know.  I assumed since you couldn't set the scratch
variable using the [scratch] ic tag (or can you?), that held true in perl,
but obviously that is not the case.

I'm including my finished code in case someone else is looking to do
something similar. Here is my final (and working) code.

My data I am retreiving from the db ended up being a list of key/value pairs
that look like this:
1=N 2=Y 3=Y 4=N etc.

I ran into the age old problem trying to update data using checkboxes and
found no easy way to uncheck anything :)  I decided to use select boxes
instead.

[perl tables="userdb"]
@subscription_pairs = split(/\s+/, $Tag->data('userdb', 'mail_list',
$Values->{mv_username}));
    foreach $my_pair (@subscription_pairs) {
	   @subscription = split(/=/, $my_pair);
      $Scratch->{$subscription[0]} = $subscription[1];
	 }
return;
[/perl]

The page is used to select from a number of different newsletters to
subscribe to. It can be used in the account.html page from the foundation
catalog.

Here is a sample select option:

<option value="1=Y"
[if type=explicit
    compare="[scratch name=1] =~ /Y/" interpolate=1]selected[/if]>Subscribe
me to newsletter 1</option>

there is a corresponding no (N) option as well.  After some testing it seems
to work fairly well.

Actually the list of newsletters is populated from a separate table
dynamically.  If anyone wants more details, please feel free to contact me.

Ideally we would be using checkboxes, but that is for another thread :)
If anyone happens to know of an easy way to show a box has been unchecked
and pass that data to the server please let me know.

mike k.