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

#!/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.

Replies are listed 'Best First'.
Re^7: Minimisation of codes (if grep {})
by choroba (Cardinal) on Oct 01, 2015 at 12:14 UTC
    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???

        See the documentation for use. It explains what the qw(...) after the use List::Util... does in your code. Instead of cargo culting, I would recommend learning how to understand the code, where to look for things you don't understand, etc. Spoon feeding will only last so long.

        --MidLifeXis