Grep to find item in Perl array

后端 未结 6 2143
名媛妹妹
名媛妹妹 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

    I could happen that if your array contains the string "hello", and if you are searching for "he", grep returns true, although, "he" may not be an array element.

    Perhaps,

    if (grep(/^$match$/, @array)) more apt.

提交回复
热议问题