How would I use index() in this situation? Check for the presence of particular problematic characters?

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:

#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;} } }
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.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.