CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Advanced:
splitting ~~



Jul 9, 2001, 2:20 PM

Post #1 of 3 (1930 views)
splitting ~~ Can't Post

Here is my next problem.

I have been successful at setting up that when a user submits a field that has multiple values it will seperate each value with a ~~. Here is my next issue. I am using

print $q->checkbox_group('cuisine', \@cuisine, [$form_data{'cuisine'}], 'true');

The problem is, when I make modifications to the record, I don't have any checked checkboxes because it doesn't recognize the ~~, and therefore it doesn't find the values to be checked. So my question is, how do I split the field.

I hope you understand



Jul 13, 2001, 11:36 AM

Post #2 of 3 (1914 views)
Re: splitting ~~ [In reply to] Can't Post

Well, you could do something like this, I'm not used to using unless I'm writting an upload script, but try this anyway.

Say you stored your checkboxes in $checkbox,

(@checks)=split(/~~/, $checkbox);

Then you could easily determine how many boxes were checked as well.

$count = @checks; # gives the number of boxes checked.

Also, if you needed to put the values into a hash, you could do this.

foreach $check (@checks){

I use this method all the time and it's great for file manipulations.

This answer seems too simple for your question but maybe it'll help.


Administrator / Moderator

Jul 14, 2001, 3:09 PM

Post #3 of 3 (1903 views)
Re: splitting ~~ [In reply to] Can't Post

# initiate instance 
my $in = CGI->new();

# create a sample delimited line
my $templine = '1~~3~~6~~9';

# simple array
my @fields = ( 1 .. 15 );

# create array of items split on ~~
my @checked = split( /~~/, $templine );

# let know the values that should already be checked.
$in->param( 'test' => @checked );

# output new checkbox group.
print $in->checkbox_group(
-name => 'test',
-values => \@fields,
-linebreak => 1


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives