in reply to Re^4: Minimisation of codes (if grep {})
in thread Minimisation of codes (if grep {})

Instead of
any { Panc }

use

any { /^\QPanc\E$/ }

the same way you would do with grep.

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^6: Minimisation of codes (if grep {})
by ravi45722 (Pilgrim) on Oct 01, 2015 at 12:10 UTC
    #!/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 { /^\QPanc\E$/ } @pantry; #$total++ if grep { /^\Qpanc\E$/ } @pantry; print "$total";

    Errors: Use of uninitialized value $_ in pattern match (m//) at /root/prac/CDR/tr.pl line 8. Can't locate object method "any" via package "Panc" (perhaps you forgot to load "Panc"?) at /root/prac/CDR/tr.pl line 8.

      You're trying to find an element in a list. But, I can't find the element "any" in your function list on line 3. The function wasn't imported.
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

        http://www.perlmonks.org/?node_id=1143505 mentioned to use List::Util . I download & install it. As per the manual said I tried upto there. What I have to do if i want to include "any" in that function???