A pipe operator exists on perl v5.42?
You know how many languages have a "pipe" operator, either ready or in the making? Like PHP, here, for example: https://laravel-news.com/the-pipe-operator-is-coming-to-php-85
Well, Perl v5.42 (almost) has that too! Check these examples:
$ perl -E 'say "Alexander"->&CORE::substr(1, 3);'
lex
$ perl -E 'say ","->&CORE::join(qw/ 10 20 30 /);'
10,20,30
I believe this would work with any user defined or imported subroutine too, instead of the core functions (there you get to omit the "CORE::").
It is not a 5.42 thing:
$ perl -E 'print "lbarfThis is perl versionblarfAlexander"->CORE::substr(5, 20);print " ",$^V'
This is perl version v5.16.3
This is just normal Perl 5 behavior, although your need v5.16 or later for CORE.
Here's a demonstration that we build up in [Intermediate Perl](https://www.intermediateperl.com/) (and as a gist where I might expand this). The problem is that the arrow operator is under documented in perlop.
#!/usr/bin/perl { package Parent; sub bar { print "Parent: $_[0]" . "\n" } } { package Foo; use parent qw(Parent); sub bar { print $_[0] . "\n" } } print "# the invocant\n"; my $string = 'Foo'; $string->bar; my $blessed = bless {}, $string; $blessed->bar; print "\n# the method\n"; my $method = 'bar'; $string->$method; $blessed->$method; # in SUPER, the virtual namespace that looks in @ISA # this looks in the current package, not the package of # the object. For this to work in main::, main needs a # parent class print "\n# main super class\n"; our @ISA = qw(MainSuper); { package MainSuper; sub bar { print "MainSuper: $_[0]" . "\n" } } $string->SUPER::bar(); $blessed->SUPER::bar(); # Now start in Foo instead, and get what you probably wanted. # Check out the SUPER module on CPAN that changes this oddity. print "\n# Foo super class\n"; { package Foo; $string->SUPER::bar(); $blessed->SUPER::bar(); } # Now, specify any sub you like: print "\n# arbitrary sub\n"; sub quux { print "quux: @_" . "\n" } $string->main::quux( 3, 7, 1 ); # really quux( $string, 3, 7, 1 ) $blessed->main::quux( 7, 3, 1 ); # really quux( $blessed, 7, 3, 1 ) # compare this with can, which returns a code ref is it can resolve # that method, but where you have to supply the first argument yourself print "\n# can\n"; my $coderef = $blessed->can('bar'); $coderef->($blessed); $coderef->($string); # but CORE is another package, and its does the same thing you just # saw in main. This is a v5.16 thing, but it's using the { print "\n# CORE::substr\n"; if( $] CORE::substr( 0, 2 ), "\n"; # really substr( $string, 0, 2 ) print $blessed->CORE::substr( 3, 4 ), "\n"; # really substr( $blessed, 3, 4 ) }You can run this under v5.8.9 and it works fine (skipping the CORE bits). It probably runs fine on earlier Perls too but I don't have those lying around.
As for the pipe operator part of this post, the arrow is not going to do that. A proper pipe operator would feed all of the values from the left hand side to the right hand argument list. The arrow isn't going to do that.
A pipe operator would be good and totally consistent with Perl relationship with unix. You want to check out my Sub::Genius module, which allows you do this using concurrent semantics. There are other modules that do this kind of thing, but as far as I know the concurrent semantics are unique to Sub::Genius. I gave a talk on it when everyone was hiding from covid and we didn't have a Perl conference. The drawback of course is it's "plan" based and not code based like what you're suggesting. I still like it.
https://metacpan.org/pod/Sub::Genius
Other modules (noted in my POD at the time of writing):
Pipeworks, Sub::Pipeline, Process::Pipeline