All:
I am in the process of converting a lot of shell scripts to Perl. I am having a problem with the following:

#!/usr/bin/ksh GrepList=`sed '/^ *$/d;/^#/d' traplist.in 2>/dev/null` grep -ilF "$GrepList" out/do* 2>/dev/null | xargs -i mv {} ./capture 2 +>/dev/null

This isn't the entire script, but it is in a continual loop.
The mv is in a race condition that is beyond my control and the GrepList changes over time.

Some of the limitations of the shell script implementation are:
1. The item in the GrepList that matched isn't recorded
2. The grep fails if the string is wrapped (imbedded) newline

I came up with the following (with help from the CB) as a start (code doesn't exactly match)

#!/usr/bin/perl my @checklist; my @testfile; my $rulenames; open (FILE,"filename"); while (<FILE>) { next if ( $_ =~ /^ *$/ || $_ =~ /^#/ ); push @checklist , $_; } chomp @checklist; close (FILE); my $GrepList = join '|', map "($_)", @checklist; @ARGV = <*>; if (@ARGV) { undef $/; while (<>) { $_ =~ s/\n//; next unless ($_ =~ /$GrepList/i); print "$ARGV : $+\n"; } }

The final product will store the time stamp of the traplist file and only update on change and fix the obvious errors, but I am more concerned with the raw functionality.

What I am trying to accomplish is the following:

  • Match on any item in list
  • Stop after first match
  • Remember what matched
  • Be as fast as possible using the least amount of resources (I know - you trade one for the other)

    What I can't do is:

  • Slurp in the file
  • Build an ever increasing string
  • Make the assumption that the string won't wrap 3 or more lines (though unlikely)

    I originally envisioned what I do when I do a word search. You scan using your finger until you come across a letter that starts a word you are looking for. You follow it until you get a match or until you realize it is a dead end. If it is a dead end, you keep on going having forgot everything that came before.

    Unfortunately, I don't believe there is a way to tell RegEx to start paying attention on a partial match.

    Any ideas?

    Limbic~Region


    In reply to Shell Script Woes by Limbic~Region

    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.