English 中文(简体)
如何在Perl找到一种检验办法?
原标题:Best Way of Checking a String has one of Many Values in Perl?
  • 时间:2011-10-01 19:35:02
  •  标签:
  • perl

我在《佩勒法典》的中间点就这样说,我发现自己写下一条法典线的恶魔。 即便如此,也没有什么捷径,也只有比这一权利更好的途径?

因此,有更好的办法:

unless($config->{ case_transform } eq  NONE  || 
       $config->{ case_transform } eq  UPPER  ||
       $config->{ case_transform } eq  LOWER  ||
       $config->{ case_transform } eq  CAPITAL  ||
       $config->{ case_transform } eq  RANDOM )
{
    $config->{ case_transform } =  NONE ;
}
最佳回答
问题回答
my %good_value = map { $_ => 1 } qw( NONE UPPER LOWER CAPITAL RANDOM );

unless $good_value{$config->{case_transform}) {
    $config->{case_transform} =  NONE ;
}
unless ($config->{ case_transform } =~ /^(NONE|UPPER|LOWER|CAPITAL|RANDOM)$/)
{
  ...
}
$config->{ case_transform } =  NONE  unless $config->{ case_transform } =~ /^(?:UPPER|LOWER|CAPITAL|RANDOM)$/;




相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...