Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: grep not working as expected

by imp (Priest)
on Oct 17, 2006 at 22:31 UTC ( #578916=note: print w/ replies, xml ) Need Help??


in reply to grep not working as expected

This isn't doing what you think:

grep { /$q->param('report_type')/ } (qw/case_id hosp_alias sender rece +iver/)
Regular expressions are interpolated, but not evaluated.

What you want instead is:

grep { $q->param('report_type') eq $_ } (qw/case_id hosp_alias sender +receiver/)
Or:
my $report_type = $q->param('report_type'); grep { $report_type eq $_ } (qw/case_id hosp_alias sender receiver/)
And to avoid checking a long list you can get only the first match by using List::Util as follows:
use List::Util qw( first ); if ( first { $report_type eq $_ } (qw/case_id hosp_alias sender receiv +er/)) { }


Comment on Re: grep not working as expected
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://578916]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2014-04-19 03:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (475 votes), past polls