Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I don't think your solution is that bad. If you want to get rid of the two reverse, I think you have to buy and additional list function instead, for instance:
List::MoreUtils::after_incl { $_ !~ /DBIC/ } List::MoreUtils::after_incl { /DBIC/ } List::MoreUtils::before { /Dancer/ } @YourList
I consider this even more ugly. Alternatively you could try
my $partition=0; my @parts = List::MoreUtils::part { if($pivots[0]) { if($partition % 2 == 0) { if($_ =~ $pivots[0]) { ++$partition; } } else { if($_ !~ $pivots[0]) { ++$partition; shift @pivots; } } } $partition } qw<eval DBIC::3 DBIC::2 DBIC::1 MyApp::3 MyApp::2 MyApp::1 Dancer::3 + Dancer::2 Dancer::1>; print join(',',@{ $parts[2] }),"\n";
Whether this is more readable, is something to be questioned, but at least the code can be generalized easier to more than 2 "pattern changes". However, it silently assumes that part traverses the list left to right, which is not guaranteed by the documentation.

Another solution (which does not use reverse) would be

my @input=qw<eval DBIC::3 DBIC::2 DBIC::1 MyApp::3 MyApp::2 MyApp::1 D +ancer::3 Dancer::2 Dancer::1>; my @firsts=@input[0..@input-2]; my @seconds=@input[1..@input-1]; my $inside=0; my @result; List::MoreUtils::pairwise { if($inside == 1) { my $pat=qr(Dancer); push @result,$a; if($a !~ $pat && $b =~ $pat) { $inside=-1; } } elsif($inside == 0) { my $pat=qr(DBIC); if($a =~ $pat && $b !~ $pat) { $inside=1; } } } @firsts, @seconds; print("@result\n");
but this is forcing the pairwise function to something in a way it was not really meant to be used (since the result of pairwise is never used).
Maybe you are better off writing a conventional loop and storing the state (inside / outside your pattern sequence) in a status variable, similar to my part example, but without (mis-)using List::MoreUtils.

Ronald Fischer <>

In reply to Re: List::MoreUtils before, after and ... between? by rovf
in thread List::MoreUtils before, after and ... between? by Boldra

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (4)
    As of 2017-12-11 06:24 GMT
    Find Nodes?
      Voting Booth?
      What programming language do you hate the most?

      Results (286 votes). Check out past polls.