Learning Perl Objects, References amp;amp; Modules [Electronic resources] نسخه متنی

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

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

Learning Perl Objects, References amp;amp; Modules [Electronic resources] - نسخه متنی

Randal L. Schwartz

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

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

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














3.4 Dropping Those Braces


Most of
the time, the dereferenced array reference is contained in a simple
scalar variable, such as @{$items} or
${$items}[1]. In those cases, the curly braces can
be dropped, unambiguously, forming @$items or
$$items[1].

However, the braces cannot be dropped if the value within the braces
is not a simple scalar variable. For example, for
@{$_[1]} from that last subroutine rewrite, you
can't remove the braces.

This rule also means that it's easy to see where the
"missing" braces need to go. When
you see $$items[1], a pretty noisy piece of
syntax, you can tell that the curly braces must belong around the
simple scalar variable, $items. Therefore,
$items must be a reference to an array.

Thus, an easier-on-the-eyes version of that subroutine might be:

sub check_required_items {
my $who = shift;
my $items = shift;
my @required = qw(preserver sunscreen water_bottle jacket);
for my $item (@required) {
unless (grep $item eq $_, @$items) { # not found in list?
print "$who is missing $item.\n";
}
}
}

The only difference here is that the
braces were removed for @$items.



/ 199