Not a great improvement on the other solutions (below). However, making a single structure saves space and allows for a way to easily see things in the debugger (as shown). Also, no need to scan the list again to obtain the max length.

#!/usr/bin/perl -w use strict; my $maxLen = 0; my $aline = qq~an interesting line of text I would like to scan I see +I see I see~; my @regexes = (['first',qr/should fail/,0] , ['second','like',0] , ['t +hird',qr/I/,0] , ['fourth',qr/scan/,0]); sub niceOutput {for(@regexes){ printf "%-${main::maxLen}s %30d\n", $_- +>[1],$_->[2] if $_->[2] > 0} } sub resetRegexes {for(@regexes){$_->[2] = 0}} sub rexyScan {my $Len = 0; for my $n(@regexes){ ++$n->[2] while ($ali +ne=~m/$n->[1]/g); $Len = length $n->[1]; if($Len > $maxLen) { $main:: +maxLen = $Len } }; } &rexyScan; &niceOutput;

Debugger shows @regexes:

main::(-e:1): 0 DB<1> @regexes = (['first',qr/interesting/,0] , ['second','like',0] +, ['third',qr/I/,0] , ['fourth',qr/scan/,0]); DB<2> x @regexes 0 ARRAY(0x569bf962c388) 0 'first' 1 (?^u:interesting) -> qr/(?^u:interesting)/ 2 0 1 ARRAY(0x569bf95f6650) 0 'second' 1 'like' 2 0 2 ARRAY(0x569bf95f68d8) 0 'third' 1 (?^u:I) -> qr/(?^u:I)/ 2 0 3 ARRAY(0x569bf95f6428) 0 'fourth' 1 (?^u:scan) -> qr/(?^u:scan)/ 2 0 DB<3>

Celebrate Intellectual Diversity


In reply to Re: Filter output based on values by InfiniteSilence
in thread Filter output based on values by LexPl

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.