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

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

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

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

Randal L. Schwartz

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

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

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














8.3 The Extra Parameter of Method Invocation


The invocation of:

Class->method(@args)

attempts to invoke the subroutine Class::method as:

Class::method("Class", @args);

(If the subroutine can't be found, inheritance kicks
in, but you'll learn about that later.) This means
that you get the class name as the first parameter or the only
parameter, if no arguments are given. You can rewrite the
Sheep speaking subroutine as:

sub Sheep::speak {
my $class = shift;
print "a $class goes baaaah!\n";
}

The other two animals come out similarly:

sub Cow::speak {
my $class = shift;
print "a $class goes moooo!\n";
}
sub Horse::speak {
my $class = shift;
print "a $class goes neigh!\n";
}

In each case, $class
gets the value appropriate for that subroutine. But once again, you
have a lot of similar structure. Can you factor out that commonality
even further? Yesby calling another method in the same class.



/ 199