Grep to find item in Perl array

后端 未结 6 2057
名媛妹妹
名媛妹妹 2021-02-04 03:51

Every time I input something the code always tells me that it exists. But I know some of the inputs do not exist. What is wrong?

#!/usr/bin/perl

@array = <&g         


        
6条回答
  •  死守一世寂寞
    2021-02-04 04:35

    This could be done using List::Util's first function:

    use List::Util qw/first/;
    
    my @array = qw/foo bar baz/;
    print first { $_ eq 'bar' } @array;
    

    Other functions from List::Util like max, min, sum also may be useful for you

提交回复
热议问题