Of course that is possible. Perl offers all that is needed; but what is your desired output? Im guessing. You want a pipeline, a.k.a. garbage in- garbage out, so you basically want to return the (possibly modified) input as output, used as input for the next pipeline subroutine.

If you make your stream into an object which is returned by each processor, you can chain your processors like methods:

my $result = $obj->processor_1->processor_2($argument)->processor_3;

If you want to accumulate results for each pass, you could include a result container in the object itself. This is one way to do it, TIMTOWTDI of course:

#!/usr/bin/perl use List::Util qw(min max); use Data::Dumper; my $ary = [12,3,4,5,7,15,8]; my $obj = bless [ $ary, {} ], __PACKAGE__; sub count { $_[0]->[1]->{count} = @{$_[0]->[0]}; $_[0]; } sub min_max { $_[0]->[1]->{min} = min @{$_[0]->[0]}; $_[0]->[1]->{max} = max @{$_[0]->[0]}; $_[0]; } sub esrever { $_[0]->[1]->{esrever} = [ reverse @{$_[0]->[0]} ]; $_[0]; } sub sort_inline { @{$_[0]->[0]} = sort {$a<=>$b} @{$_[0]->[0]}; $_[0]; } sub append_stuff_inline { $_ .= $_[1] for @{$_[0]->[0]}; $_[0]; } my $result = $obj->min_max->append_stuff_inline(".foo")->count->esreve +r->sort_inline; print Dumper($result); __END__ $VAR1 = bless( [ [ '3.foo', '4.foo', '5.foo', '7.foo', '8.foo', '12.foo', '15.foo' ], { 'min' => 3, 'max' => 15, 'esrever' => [ '8.foo', '15.foo', '7.foo', '5.foo', '4.foo', '3.foo', '12.foo' ], 'count' => 7 } ], 'main' );

The first element of the anonymous array $result is the modified array, the second is an anonymous hash containing the output of each pipeline subroutine.

Of course, you could name the first argument to each method (i.e. $_[0]) adequately as $self, that makes no difference, but it might be easier to tell what is going on.

With the above subs, you could also say

my @chain = qw(min_max count sort_inline esrever); my ($result) = map { $obj->$_ } @chain;

which of course doesn't let you pass in additional arguments to the methods called, which is why I didn't include append_stuff_inline() since that would be a no-op..

Perl allows you to

It is up to you how you organize your data, what you pass into your subs, what you modify and what you return.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

In reply to Re: multiple consumer of an array by shmem
in thread multiple consumer of an array by bagyi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.