Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

>>Remove regexes from perl, what’s left?

qw, qr, references, multiline regexes, a far advanced OO ecosystem, Data::Dumper, map, grep, pack/unpack, DBM, ``, top class unicode handling, given/when, functional programming etc etc.

In fact I've barely scratched the surface.

You must grok Perl more.



Won’t nitpick, how much of what’s useful here is unique to perl? You could make a similar list for most languages and barely scratch the surface.

top class unicode handling

This one I remember struggling with, afair due to io vs perlio layers impedance mismatch and use utf8. Not sure about now, but perl was anything but unicode for the clueless.


OO is the part of Perl that I grok the least. What about it makes it "far advanced" compared to, say, Java or C++ versions of OO?


https://metacpan.org/pod/Moose

Moose is definitely what I go for when I have to use OO with Perl, this more than a decade old and stable for production use cases.

Its based on Class::MOP, which is in turn based on Meta Object Protocol, the same concepts on which CLOS(Common Lisp Object System) is based on. Its always nice to have CLOS goodness in Perl. For eg- https://metacpan.org/dist/Moose/view/lib/Moose/Manual/Method... these methods like before, after, around do fix need for design patterns to a large extent.

But of course the more you explore, the more you discover the possibilities with this.

To a large extent I think Perl brings OO and functional paradigm in a far better package than Python does.

Perhaps HOP needs a new chapter for OO given how few people are aware of this.


The key idea in CLOS is multi method dispatch, which Moose does not provide.

Moose out of the box has its own set of problems, leading to other workarounds, e.g.

Moo (a similar but much less bloated solution)

MooseX::Extended - Moose with more sensible/correct defaults

https://metacpan.org/dist/MooseX-Extended/view/lib/MooseX/Ex...


OO in Perl is lower level compared to Java or C++, so e.g. instead of having a class construct, you have to simulate a class - typically by binding (blessing) a data structure to a namespace. Then any functions in the namespace become methods that can be called via the data structure (object).

In practice, this has turned out to be a mixed blessing because of how tedious it is to do this repeatedly. So over the years there have been many libraries created to make this easier, each with different features.

There's currently work underway to modernise Perl's built in OO to address these problems.

On the other hand, this makes some things easier, e.g. Design by Contract can be added to Perl just by writing a library.

Another example, adding traits to PHP required updating PHP itself, whereas in Perl there are libraries to do that.


given/when are deprecated and will be removed in a future release.

References are a PITA - cumbersome to use, and they make code less readable.

Perl doesn't have first class functions (you can pass or return functions via references, but that's cumbersome and less readable compared to languages with better FP support).


>>given/when are deprecated and will be removed in a future release.

given/when won't be removed, too much back wards compatibility issues.

>>References are a PITA - cumbersome to use, and they make code less readable.

Depends what you mean readable though. In python you can't tell whats a variable and whats a list, and whats a dictionary by looking. One can claim whole language is unreadable since variables are needed at every step.

>>but that's cumbersome and less readable compared to languages with better FP support

Sure let them add all the other practical goodness of Perl, then we can use them.


Consider

    % perl -v | head -2

    This is perl 5, version 40, subversion 0 (v5.40.0) built for x86_64-linux
    % 
    % perl -E 'use feature "switch"; my ($x, $y); given ($x) { $y = 1 when /^abc/ }'
    given is deprecated at -e line 1.
    when is deprecated at -e line 1.
This is also mentioned in the docs:

  Smartmatch is now seen as a failed experiment and was marked as deprecated in Perl 5.37.10. 
  This includes the when and given keywords, as well as the smartmatch operator ~~. 
  The feature will be removed entirely in the Perl 5.42.0 production release.
https://perldoc.perl.org/perldeprecation#Smartmatch

>> In python you can't tell whats a variable and whats a list, and whats a dictionary by looking.

In Perl, sigils are used to distinguish between scalars/lists/hashes. Sigils and references are not the same thing.

https://www.perl.com/article/on-sigils

https://perldoc.perl.org/perlreftut




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: