Perl: if ( element in list )

后端 未结 10 633
栀梦
栀梦 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:42

    if( $element ~~ @list ){
       do_task
    }
    

    ~~ is the "smart match operator", and does more than just list membership detection.

提交回复
热议问题