Thank you, it was indeed an error on my part. I originally used $1 in the filter's regexp which does generate a similar error message (that was part of what misled me later). I also pruned a test case now so there aren't thousands of error messages confusing things (which also misled me). For the test case I deleted all but 4 content files (20, 21.5800, 21.5802, 22), then compiled that to get a much smaller list file. And I found a way to run the filter from a command-line interface rather than my application's TUI. I uploaded all the test case files to our server.

Here's the nonworking code without a named variable, just using $1:

test$ grep '#/INT' dir1list.pl -A1 -B3 } my $rule = Path::Iterator::Rule->new; if ($id =~ /^([0-9A-F]{2})/) { $rule->and( sub { m#/INT $1# } ); }

And here's the output, as expected except for the "Use of uninitialized value $1 in regexp compilation" lines and the fact that "Searching file INT 20 DOS 1 TERMINATE PROGRAM.txt" is displayed. (The filter is intended to avoid this scan specifically, as the unique ID indicates that we only want to search pathnames matching "/INT 21".)

test$ ./dir1list.pl --listing TheList/INTERRUP.LST --source source --f +ind --summary --link 21.58 From "[Link command line switch]": Hyperlink selected: INT 21/AH=58h Found: "INT 21 - DOS 2.11+ - GET OR SET MEMORY ALLOCATION STRATEGY (AH +=58h/AL=00h,01h)" Use of uninitialized value $1 in regexp compilation at ./dir1list.pl l +ine 1166, <$array_lstff[...]> line 125. Searching file INT 20 DOS 1 TERMINATE PROGRAM.txt Use of uninitialized value $1 in regexp compilation at ./dir1list.pl l +ine 1166. Searching file INT 2158 DOS 211 GET OR SET MEMORY ALLOCATION STRATEGY. +txt source/Interrupt List/INT 21 DOS Function Calls/INT 2158 DOS 211 GET O +R SET MEMORY ALLOCATION STRATEGY.txt Found: "INT 21 - DOS 5+ - GET OR SET UMB LINK STATE (AH=58h/AL=02h,03h +)" Use of uninitialized value $1 in regexp compilation at ./dir1list.pl l +ine 1166, <$array_lstff[...]> line 323. Searching file INT 20 DOS 1 TERMINATE PROGRAM.txt Use of uninitialized value $1 in regexp compilation at ./dir1list.pl l +ine 1166. Searching file INT 2158 DOS 211 GET OR SET MEMORY ALLOCATION STRATEGY. +txt Use of uninitialized value $1 in regexp compilation at ./dir1list.pl l +ine 1166. Searching file INT 2158 DOS 5 GET OR SET UMB LINK STATE.txt source/Interrupt List/INT 21 DOS Function Calls/INT 2158 DOS 5 GET OR +SET UMB LINK STATE.txt

And here's what I reconstructed from my editor as the wrong code I tried, note the minus sign instead of equals sign:

test$ grep '#/INT' minuslst.pl -A1 -B3 my $rule = Path::Iterator::Rule->new; if ($id =~ /^([0-9A-F]{2})/) { my $int - $1; $rule->and( sub { m#/INT $int# } ); }

Here's what this runs like. Note the error messages, including some I didn't notice previously reading "Useless use of subtraction (-) in void context at ./minuslst.pl line 1166." and "Use of uninitialized value $int in subtraction (-) at ./minuslst.pl line 1166, <$array_lstff...> line 125." (It is unfortunate that the subtraction like that only warrants an error at run time and doesn't cause perl to refuse to run the program. I do of course have "use warnings;" and "use strict;" already.) After that the error message that I previously quoted appears multiple times, and the INT 20 file is also searched again.

test$ ./minuslst.pl --listing TheList/INTERRUP.LST --source source --f +ind --summary --link 21.58 Useless use of subtraction (-) in void context at ./minuslst.pl line 1 +166. From "[Link command line switch]": Hyperlink selected: INT 21/AH=58h Found: "INT 21 - DOS 2.11+ - GET OR SET MEMORY ALLOCATION STRATEGY (AH +=58h/AL=00h,01h)" Use of uninitialized value $int in subtraction (-) at ./minuslst.pl li +ne 1166, <$array_lstff[...]> line 125. Use of uninitialized value $int in regexp compilation at ./minuslst.pl + line 1167, <$array_lstff[...]> line 125. Searching file INT 20 DOS 1 TERMINATE PROGRAM.txt Use of uninitialized value $int in regexp compilation at ./minuslst.pl + line 1167. Searching file INT 2158 DOS 211 GET OR SET MEMORY ALLOCATION STRATEGY. +txt source/Interrupt List/INT 21 DOS Function Calls/INT 2158 DOS 211 GET O +R SET MEMORY ALLOCATION STRATEGY.txt Found: "INT 21 - DOS 5+ - GET OR SET UMB LINK STATE (AH=58h/AL=02h,03h +)" Use of uninitialized value $int in subtraction (-) at ./minuslst.pl li +ne 1166, <$array_lstff[...]> line 323. Use of uninitialized value $int in regexp compilation at ./minuslst.pl + line 1167, <$array_lstff[...]> line 323. Searching file INT 20 DOS 1 TERMINATE PROGRAM.txt Use of uninitialized value $int in regexp compilation at ./minuslst.pl + line 1167. Searching file INT 2158 DOS 211 GET OR SET MEMORY ALLOCATION STRATEGY. +txt Use of uninitialized value $int in regexp compilation at ./minuslst.pl + line 1167. Searching file INT 2158 DOS 5 GET OR SET UMB LINK STATE.txt source/Interrupt List/INT 21 DOS Function Calls/INT 2158 DOS 5 GET OR +SET UMB LINK STATE.txt

Finally, the correct code that I intended to try before:

test$ grep '#/INT' dirlist.pl -A1 -B3 my $rule = Path::Iterator::Rule->new; if ($id =~ /^([0-9A-F]{2})/) { my $int = $1; $rule->and( sub { m#/INT $int# } ); }

As you suggested, this actually works just fine. The run shows no more error messages and the INT 20 and INT 22 files aren't searched, as intended:

test$ ./dirlist.pl --listing TheList/INTERRUP.LST --source source --fi +nd --summary --link 21.58 From "[Link command line switch]": Hyperlink selected: INT 21/AH=58h Found: "INT 21 - DOS 2.11+ - GET OR SET MEMORY ALLOCATION STRATEGY (AH +=58h/AL=00h,01h)" Searching file INT 2158 DOS 211 GET OR SET MEMORY ALLOCATION STRATEGY. +txt source/Interrupt List/INT 21 DOS Function Calls/INT 2158 DOS 211 GET O +R SET MEMORY ALLOCATION STRATEGY.txt Found: "INT 21 - DOS 5+ - GET OR SET UMB LINK STATE (AH=58h/AL=02h,03h +)" Searching file INT 2158 DOS 211 GET OR SET MEMORY ALLOCATION STRATEGY. +txt Searching file INT 2158 DOS 5 GET OR SET UMB LINK STATE.txt source/Interrupt List/INT 21 DOS Function Calls/INT 2158 DOS 5 GET OR +SET UMB LINK STATE.txt test$

In reply to Re^2: Interpolate variable into regexp at time of definition rather than execution, as a filter for Path::Iterator::Rule by ecm
in thread Interpolate variable into regexp at time of definition rather than execution, as a filter for Path::Iterator::Rule by ecm

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.