in reply to Searching with grep

grep iterates over the list you give it, assigns each member to $_ and evaluates the given expression or code. In this case, you try
{ date => '20161010', day => 'Monday' } =~ /^$search$/

which clearly isn't true. Just modify your expression to match the date part of each element:

my $result = ( grep $_->{date} =~ /^$search$/, @$data ) ? 'Found' : 'N +ot Found';

Update: Note that for larger lists, any from List::Util might be faster if you just want to know whether such an element exists. It also specifies the intent more clearly.

use List::Util qw{ any }; my $result = ( any { $_->{date} =~ /^$search$/ } @$data ) ? 'Found' : +'Not Found';

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Searching with grep
by Anonymous Monk on Mar 23, 2016 at 18:20 UTC
    Thanks for the info. I also noticed that if I use a reg exp. in the "grep", it will still match if this value:  my $search = "2016101";
    I changed the result line to this:
    my $result = ( grep $_->{date} eq $search, @{ $data } ) ? 'Found' : 'N +ot Found';
    My list isn't too big and it is one less module to load into to rest of the code.
Re^2: Searching with grep
by Anonymous Monk on Mar 23, 2016 at 18:24 UTC
    I like your "Choroba" whatever that means code:
    my $q; ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,