http://www.perlmonks.org?node_id=999304


in reply to Argument for Perl ( again and again )

Perl is not an OO language; it's a multi-paradigm language giving you the flexibility to mix OO code with other styles of programming.

Whatsmore, Perl's OO system allows you far more power and flexibility for OO code than Java or Java-inspired OO systems (PHP's is Java-inspired). And projects like Moose allow you to take advantage of that power without tearing your hair out!

Java's version of OO is very limited. It's single-inheritance, class-based OO. Many Java developers seem to believe that's the only true form of OO. Some will acknowledge that multiple inheritance is occasionally useful, but that it can also introduce problems (e.g. diamond inheritance). Few are aware that other entirely non-class-based forms of OO are also possible, such as aspect-oriented, role-oriented and prototype-based OO.

Here's an example in Perl (with Moose) using both classes and roles to take a plain old instance of the Person class and install a new method for that object only (not the entire Person class).

use v5.14; package Person 1.0 { use Moose; has name => (is => 'ro'); }; my $alice = Person->new(name => 'Alice'); my $bob = Person->new(name => 'Bob'); # Teach Bob to sing! Moose::Util::ensure_all_roles( $bob, Moose::Meta::Role->create_anon_role( methods => { sing => sub { say "lalala" } }, ) ); foreach my $person ($alice, $bob) { say $person->name, " can you please sing?"; if ($person->can('sing')) { $person->sing; } else { say $person->name, " cannot sing!"; } }

So even if Perl isn't an "OO language", it provides an arguably better and more complete OO programming environment than Java.

Also, while other languages may "have" regular expressions, these are generally just "match" and "replace" type functions which can be passed a regular expression and a string. In Perl, they're an integral part of the language...

use v5.10; my $count = 0; my $var = "foo <> foo <> foo"; $var =~ s ( fo{2} ) { ++$count; }gex; say $var;

Whatsmore, regular expressions in Perl are far more powerful. (More powerful even than those languages that provide the "Perl-compatible" regexp engine - this regexp library was compatible with a very old version of Perl; Perl's improved since then.)

Lastly, I'd say you undervalued CPAN. It's not just a repository of libraries; there's the whole infrastructure that goes with it:

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'