<?xml version="1.0" encoding="windows-1252"?>
<node id="578911" title="grep not working as expected" created="2006-10-17 18:14:23" updated="2006-10-17 14:14:23">
<type id="115">
perlquestion</type>
<author id="351094">
davidj</author>
<data>
<field name="doctext">
Fellow monks,&lt;BR&gt;
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.&lt;BR&gt;&lt;BR&gt;
The form part looks like this:
&lt;code&gt;
&lt;select name="report_type" &gt;
&lt;option value="case_id"&gt;case_id&lt;/option&gt;
&lt;option value="hosp_alias"&gt;hosp_alias&lt;/option&gt;
&lt;option selected="selected" value="sender"&gt;sender&lt;/option&gt;
&lt;option value="receiver"&gt;receiver&lt;/option&gt;
&lt;option value="date"&gt;date&lt;/option&gt;
&lt;/select&gt;
&lt;/code&gt;
After selecting any of the option (in this case sender), I do the following in the cgi script:
&lt;code&gt;
print "param=" . $q-&gt;param('report_type') . "&lt;BR&gt;";
if( grep { /$q-&gt;param('report_type')/ } (qw/case_id hosp_alias sender receiver/) ) {
    print "we are getting the list&lt;BR&gt;";
} else {
    print "we are NOT getting the list&lt;BR&gt;";
}
&lt;/code&gt;
The output I get is this:&lt;BR&gt;
&lt;code&gt;
param=sender
we are NOT getting the list
&lt;/code&gt;
At this point I am not modifying in any way the query parameters after they are sent to the script.&lt;BR&gt;
If I understand grep correctly, I should be getting:
&lt;code&gt;
param=sender
we are getting the list
&lt;/code&gt;
If I take this part and put it in a simple script, I works correctly:
&lt;code&gt;
#!/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";
}
&lt;/code&gt;
output:
&lt;code&gt;
getting the list
&lt;/code&gt;
Why am I not getting what is expected? The value is verifiably in the list. The grep syntax is correct. &lt;BR&gt;&lt;BR&gt;
As always your assistance is much appreciated.&lt;BR&gt;
davidj</field>
</data>
</node>
