小编liv*_*e75的帖子

如何在perl中将变量用作正则表达式修饰符?

我正在编写一个抽象函数,它将询问用户一个给定的问题,并根据给定的正则表达式验证答案.重复该问题,直到答案与验证正则表达式匹配.但是,我还希望客户端能够指定答案是否必须符合大小写.所以像这样:

sub ask {
    my ($prompt, $validationRe, $caseSensitive) = @_;
    my $modifier = ($caseSensitive) ? "" : "i";
    my $ans;
    my $isValid;

    do {
        print $prompt;
        $ans = <>;
        chomp($ans);

        # What I want to do that doesn't work:
        # $isValid = $ans =~ /$validationRe/$modifier;

        # What I have to do:
        $isValid = ($caseSensitive) ?
            ($ans =~ /$validationRe/) :
            ($ans =~ /$validationRe/i);

    } while (!$isValid);

    return $ans;
}
Run Code Online (Sandbox Code Playgroud)

Upshot:有没有办法动态指定正则表达式的修饰符?

regex perl dynamic case-sensitive modifier

8
推荐指数
1
解决办法
2157
查看次数

使用与结构内部的位字段结合的正确语法

我有以下系列的结构.

struct FooWord1
{
    unsigned int Fill      :  8;
    unsigned int someData1 : 18;
    unsigned int someData2 : 6;
};

struct FooWord2
{
    unsigned int Fill      :  8;
    union
    {
        unsigned int A_Bit : 1;
        unsigned int B_Bit : 1;
    };
    unsigned int someData3 : 23;
};

struct Foo_Data
{
    FooWord1 fooWord1;
    FooWord2 fooWord2;
    FooWord3 fooWord3;  // similar to FooWord1
    FooWord4 fooWord4;  // similar to FooWord1
    FooWord5 fooWord5;  // similar to FooWord1
};

Foo_Data fooArray[SIZE];
Run Code Online (Sandbox Code Playgroud)

数据fooArray从网络消息逐字节复制.someData3如果我们不使用带有1位字段( …

c++ struct unions bit-fields

6
推荐指数
1
解决办法
556
查看次数

在 Perl 中,正则表达式中的捕获组数量是否有限制?

正则表达式中的捕获组数量是否有限制?我曾经认为它是 9 ($1 ... $9),但在 perlre 文档中没有找到任何内容来证实这一点。事实上,下面的代码显示至少有 26 个。

#!/usr/local/bin/perl

use strict;
use warnings;

my $line = " a b c d e f g h i j k l m n o p q r s t u v w x y z ";

my $lp = "(\\w) ";
my $pat = "";
for (my $i=0; $i<26; $i++)
{
   $pat = $pat . $lp;
}

$line =~ /$pat/;
print "$1 $2 $3 $24 $25 $26\n";
Run Code Online (Sandbox Code Playgroud)

请注意,这个问题: How much capture …

regex perl capturing-group

5
推荐指数
2
解决办法
308
查看次数

无法在CREATE TABLE中使用内联约束

我在Oracle中有以下作为CREATE TABLE:

CREATE TABLE cs2_users (
    empnum     varchar2(12) PRIMARY KEY,
    toolsId    varchar2(20) 
        CONSTRAINT nn_cs2_users_toolsId NOT NULL
        CONSTRAINT fk_cs2_users_users FOREIGN KEY REFERENCES users.userid,
    admin      number(1,0) DEFAULT 0
        CONSTRAINT nn_cs2_users_admin NOT NULL
        CONSTRAINT ck_cs2_users_admin (admin IN (0,1)),
    givenname  varchar2(30) NOT NULL,
    middlename varchar2(30),
    sn         varchar2(30) NOT NULL,
    mail       varchar2(50) NOT NULL
);
Run Code Online (Sandbox Code Playgroud)

但是它失败并出现此错误:

ERROR at line 5:
ORA-02253: constraint specification not allowed here`
Run Code Online (Sandbox Code Playgroud)

当我使用SQL*Plus连接时,这是版本信息:

SQL*Plus: Release 11.2.0.3.0 Production on Tue Dec 18 16:38:27 2012

Copyright (c) 1982, 2011, Oracle.  All rights reserved. …
Run Code Online (Sandbox Code Playgroud)

oracle sqlplus

4
推荐指数
1
解决办法
2996
查看次数