in reply to Minimisation of codes (if grep {})

Hello ravi45722,

By this my program is getting too late.

In addition to the if / elsif / ... / else construct suggested by Corion, you might gain a speedup by using List::Util::any in place of grep. From the documentation for List::Util:

Many cases of using grep in a conditional can be written using any instead, as it can short-circuit after the first true result.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Minimisation of codes (if grep {})
by ravi45722 (Pilgrim) on Oct 01, 2015 at 11:05 UTC

    Thanks for that. But by using  /^\Q$intermediate_array[11]\E$/ I can grep exact word. Is this List::Util::any checks for exact words or works like simple grep????

      Is this List::Util::any checks for exact words or works like simple grep????

      One of the many, many great things about Perl is the volume and quality of the documentation. It will stand you in excellent stead to become familiar with how to access it. If you have already read the relevant documentation but have not understood it then by all means describe which part is giving you the trouble so that the documentation might be made even clearer.

        #!/usr/bin/perl use Modern::Perl; use List::Util qw(first max maxstr min minstr reduce shuffle sum); my @pantry = ("Panc", "Pancake", "Panmix"); my $total = 0; $total++ if( any { Panc } @pantry); #$total++ if grep { /^\Qpanc\E$/ } @pantry; print "$total";

        Here its showing error. Cant use Barewords Panc at 9