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

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

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

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

Damian Conway

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

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

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


2.12. Blocks


Never place two statements on the same line .


If two or more statements share one line, each of them becomes harder to comprehend:


RECORD:
while (my $record = <$inventory_file>) {
chomp $record; next RECORD if $record eq $EMPTY_STR;
my @fields = split $FIELD_SEPARATOR, $record; update_sales(\@fields);$count++;
}

You're already saving vertical space by using K&R bracketing; use that space to improve the code's readability, by giving each statement its own line:


RECORD:
while (my $record = <$inventory_file>) {
chomp $record;
next RECORD if $record eq $EMPTY_STR;
my @fields = split $FIELD_SEPARATOR, $record;
update_sales(\@fields);
$count++;
}

Note that this guideline applies even to map and grep blocks that contain more than one statement. You should write:


my @clean_words
= map {
my $word = $_;
$word =~ s/$EXPLETIVE/[DELETED]/gxms;
$word;
} @raw_words;

not:


my @clean_words
= map { my $word = $_; $word =~ s/$EXPLETIVE/[DELETED]/gxms; $word } @raw_words;

/ 317