Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I have a string of html select options that looks like $selection in the code below. I have a variable $value might be in the list of html options in the form of $value--$hidden_value. If $value matches like in the code below I would like to 'preselect' the html select box for the user. The following code works, however it is not the way I was trying to do it. I was trying to use one regular expression instead of two like in $selection2, using a sub match $2 to just modify "> to be " selected > in place if $value matched before. How this possible? I have several perl books I have been looking in the camel book around page 200, as well as modern perl and on line did not come up with anything that worked better yet (but I did get this far) Thanks in advance!
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my ($selection,$selection2,$selection3,$value,$t2); $value = "13gr"; print "regex question: How do I modify in place in only one character +class?\n"; $selection = qq| <option value="000-F--10180">000-F <option value="11EG--10181">11EG <option value="12160--10182">12160 <option value="12164--10185">12164 <option value="12170--10186">12170 <option value="12216--12216">12216 <option value="12330--12330">12330 <option value="12480--12480">12480 <option value="12484--12484">12484 <option value="12488--12488">12488 <option value="12534--12534">12534 <option value="12756--12756">12756 <option value="12760--12760">12760 <option value="12764--12764">12764 <option value="12813--12813">12813 <option value="12A--10983">12A <option value="12B--10987">12B <option value="12BB--10347">12BB <option value="12D--10993">12D <option value="12ea--10376">12ea <option value="12JI--10438">12JI <option value="12NO--10242">12NO <option value="13gr--11117">13gr <option value="2--2--11070">2--2 <option value="22QS--33337">22QS <option value="22WO--55555">22WO <option value="22WO.1--64444">22WO.1 |; $selection2 = $selection ; $selection3 = $selection ; $selection =~ s/(\Q$value\E)/$1 selected/ ; $selection2 =~ s/((?:.*?($value)){2}).*(\">)// ; $selection3 =~ s/(?:.*?($value)){2}// ; my $t3 = $&; #print "Matches: $1, $2, $3, $4, $5, $6, $7\n"; ($t2 = $t3) =~ s/(\">)/\" selected >/ ; $selection3 .= $t2 ; print "3: $selection3\n\n"; print "value $value\n"
PS the above code is just a mockup just for an example

In reply to regex question: How do I modify in place in only one character class? by aturtle

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-26 00:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found