Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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/)) { }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://578916]
help
Chatterbox?
[LanX]: OK ... will you also come to YAPC::EU ?
[choroba]: Will Glasgow have been out of the EU by that time already?
[LanX]: nope
hippo might venture to YAPC::EU.
[choroba]: YAPC::YAEC (yet another European country)
[LanX]: they are proposing an infinite transition phase now ...
[choroba]: infinite transition implies infinite money!

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2018-02-23 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (301 votes). Check out past polls.

    Notices?