Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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 romping around the Monastery: (8)
As of 2016-02-12 03:52 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (388 votes), past polls