Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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/)
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://578916]
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: (4)
As of 2015-11-28 01:01 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (736 votes), past polls