Modern Perl blog पर विषय पर क्रोमैटिक के उत्कृष्ट हालिया ब्लॉग पोस्ट को उद्धृत करने के लिए: "पागलपन अस्पष्टता से बचने के लिए।"
इसे समझने के लिए क्यों इस तरह के वाक्य रचना उपयोगी है, यहां एक उदाहरण अपने नमूना से विकसित किया गया है:
package a;
our $fh;
use IO::File;
sub s {
return $fh = IO::File->new();
}
package a::s;
sub binmode {
print "BINMODE\n";
}
package main;
a::s->binmode; # does that mean a::s()->binmode ?
# calling sub "s()" from package a;
# and then executing sub "open" of the returned object?
# In other words, equivalent to $obj = a::s(); $obj->binmode();
# Meaning, set the binmode on a newly created IO::File object?
a::s->binmode; # OR, does that mean "a::s"->binmode() ?
# calling sub "binmode()" from package a::s;
# Meaning, print "BINMODE"
a::s::->binmode; # Not ambiguous - we KNOW it's the latter option - print "BINMODE"
अगर आपको लगता है कि * * वाक्य रचना अजीब है ... –
पर्ल न कारणों और न ही बहाने की जरूरत है। पर्ल पर्ल है। –
@pst - मैं आपको एक अजनबी को पेश करने की हिम्मत करता हूं :) – DVK