Perl: if ( element in list )

后端 未结 10 636
栀梦
栀梦 2021-01-30 06:05

I\'m looking for presence of an element in a list.

In Python there is an in keyword and I would do something like:

if element in list:
            


        
10条回答
  •  悲&欢浪女
    2021-01-30 06:52

    TIMTOWTDI

    sub is (&@) {
      my $test = shift;
      $test->() and return 1 for @_;
      0
    }
    
    sub in (@) {@_}
    
    if( is {$_ eq "a"} in qw(d c b a) ) {
      print "Welcome in perl!\n";
    }
    

提交回复
热议问题