The regex I'm using, as I clarified above isn't really a test per se - it's a part of the script which allows users to edit their data - using the form page as a template, and replacing particular lines in the HTML code with values they entered in the first place. Maybe there are better ways to do it than the following:
BTW, this script doesn't entirely work the way I'd like it to. For some reason, it can't seem to do the menu selection right. Otherwise, it works pretty well.#Read in the template HTML file with the form . $form_file = $fields{formpage}; open (FILE, "$form_file"); @form = <FILE>; $select_flag=0; foreach (@form) { foreach $key (keys %fields) { if ($_ =~ /name=\"$key\"/i) { if (($key ne "table")&&($key ne "formpage")&&($key ne "dbname" +)&&($_ !~ /meta/i)) { if ($_ =~ m/check|radio/i) { $valueplace = index($_, "value="); $value = substr($_,$valueplace+7); ($value,$junk) = split(/\"/,$value); if ($fields{$key} eq $value) { $_ =~ s/input/input checked/i; print; print "\n"; $form_flag=1; last; } next; } elsif ($_ =~ /textarea/i) { #these are the regex giving me trouble if the data has wierd charact +ers $_ =~ s/><\/textarea/>$fields{$key}<\/textarea/i; } elsif ($_ =~ m/select/i) { } else { $_ =~ s/input/input value=\"$fields{$key}\"/i; } print; print "\n"; $form_flag = 1; } } elsif ($_ =~ /select/) { $select_flag=1; } elsif (($select_flag)&&($_ =~ m/option value=/i)) { $_ =~ s/option value=\"$fields{$key}\"/option value=\" +$fields{$key}\" selected/;; } } if (!$form_flag) { print; print "\n"; next; } else {$form_flag=0; next;} } }
In reply to Re: (tye)Re: How to gracefully deal with a regex problem
by michellem
in thread How to gracefully deal with a regex problem
by michellem
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |