Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Fellow monks,
I have been scratching my head over this trying to figure out what I am doing wrong. For the life of me, I am not seeing it. I am using grep to test the value of a query paramater. The value IS in the list, but grep is not finding it. I hope I have included all the relevant information below.

The form part looks like this:
<select name="report_type" > <option value="case_id">case_id</option> <option value="hosp_alias">hosp_alias</option> <option selected="selected" value="sender">sender</option> <option value="receiver">receiver</option> <option value="date">date</option> </select>
After selecting any of the option (in this case sender), I do the following in the cgi script:
print "param=" . $q->param('report_type') . "<BR>"; if( grep { /$q->param('report_type')/ } (qw/case_id hosp_alias sender +receiver/) ) { print "we are getting the list<BR>"; } else { print "we are NOT getting the list<BR>"; }
The output I get is this:
param=sender we are NOT getting the list
At this point I am not modifying in any way the query parameters after they are sent to the script.
If I understand grep correctly, I should be getting:
param=sender we are getting the list
If I take this part and put it in a simple script, I works correctly:
#!/usr/bin/perl $p = 'sender'; if( grep { /$p/ } (qw/case_id hosp_alias sender receiver/) ) { print "getting the list\n"; } else { print "not getting the list\n"; }
output:
getting the list
Why am I not getting what is expected? The value is verifiably in the list. The grep syntax is correct.

As always your assistance is much appreciated.
davidj

In reply to grep not working as expected by davidj

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (8)
    As of 2014-07-14 07:47 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (256 votes), past polls