Perl Best Practices [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Perl Best Practices [Electronic resources] - نسخه متنی

Damian Conway

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید







12.8. Other Delimiters


Don't use any delimiters other than /.../ or m{...} .


Although Perl allows you to use

any non-whitespace character you like as a regex delimiter, don't. Because leaving some poor maintenance programmer to take care of (valid) code like this:


last TRY if !$!!~m!/pattern/!;

or this:


$same=m={===m=}=;

or this:


harry s truman was the 33rd u.s. president;

is just cruel.

Even with more reasonable delimiter choices:


last TRY if !$OS_ERROR !~ m!/pattern/!;
$same = m#{# == m#}#;
harry s|ruman was |he 33rd u.s. presiden|;

the boundaries of the regexes don't stand out well.

By sticking with the two recommended delimiters (and other best practices), you make your code more predictable, so it is easier for future readers to identify and understand your regexes:


last TRY if !$OS_ERROR !~ m{ /pattern/ }xms;
$same = ($str =~ m/{/xms == $str =~ m/}/xms);
harry( $str =~ s{ruman was }{he 33rd u.s. presiden}xms );

Note that the same advice also applies to substitutions and transliterations: stick to s/.../.../xms or s{...}{...}xms, and TR/.../.../ or TR{...}{...}.


/ 317