Perl: Matching hash keys to a regular expression

前端 未结 4 1726
渐次进展
渐次进展 2020-12-10 11:38

I\'m wondering if Perl has a built-in way to check for the existence of a hash element with a key matching a particular regex. For example:

my %h = ( \'twelv         


        
4条回答
  •  攒了一身酷
    2020-12-10 12:06

    In addition to the other answers here you can also do this with perl's grep:

    print "We have some teens\n" if grep {/.*teen/} keys %h;
    

提交回复
热议问题