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

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

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

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

Damian Conway

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

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

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







4.3. Single-Character Strings


Don't write one-character strings in visually ambiguous ways .


Character strings that consist of a single character can present a variety of problems, all of which make code harder to maintain.

A single space in quotes is easily confused with an empty string:


$separator = ' ';

Like an empty string, it should be specified more verbosely:


$separator = q{ };

# Single space

Literal tabs are even worse (and not just in single-character strings):


$separator = ' '; # Empty string, single space, or single tab???
$column_gap = ' '; # Spaces? Tabs? Some combination thereof?

Always use the interpolated \t form instead:


$separator = "\t";
$column_gap = "\t\t\t";

Literal single-quote and double-quote characters shouldn't be specified in quotation marks either, for obvious aesthetic reasons: '"', "\", '\'', "'". Use q{"} and q{'} instead.

You should also avoid using quotation marks when specifying a single comma character. The most common use of a comma string is as the first argument to a join:


my $printable_list = '(' . join(',', @list) . ')';

The ',', sequence is unnecessarily hard to decipher, especially when:


my $printable_list = '(' . join(q{,}, @list) . ')';

is just as easy to write, and stands out more clearly as being a literal. See the "Constants" guideline later in this chapter for an even cleaner solution.


/ 317