A couple of suggestions for your code:

  1. Although it works, open(IN, ,"<", $file) has an extra comma in it. Also lexical filehandles are generally considered to be better (e.g. open my $in, '<', $file or die $!;)
  2. You use the array @_ in your subs for storing data. While that's possible, @_ is generally only used to access the arguments passed into a sub, and using it the way you're doing is very likely to confuse others working with your code.
  3. Although I'm not sure what your intentions were, I suspect the regex /Date of Last Update:+/ is not doing what you expect: It'll match the string "Date of Last Update" followed by one or more colons. If you want to match the string itself multiple times, you need a group: /(?:Date of Last Update:)+/, although I'm not sure if the input file will ever contain the string "Date of Last Update:Date of Last Update:". Also, {1,} is equivalent to +.
  4. You can use your variable $substr in your regular expressions, e.g. /\Q$substr\E/ (for the meaning of \Q...\E see quotemeta).
  5. Naming a sub the same as a Perl keyword, in this case "grep", is generally a bad idea - the only exception is when you're actually trying to replace the built-in grep - because it will create much confusion as to which function is supposed to be called when, both for the readers of your code and for Perl. This confusion is why you had to call your "grep" as &grep();. Also, inside your "grep", you're calling Perl's grep, any slight mistake in syntax may call your "grep" instead and create infinite recursion.
  6. A small hint: grep { $_ =~ /Date of Last Update:/ } can be written as grep { /Date of Last Update:/ } and "... file: ".$file.": $!\n"; can be written as "... file: $file: $!\n";
  7. On style: If you find yourself using $_ a lot, over multiple lines, then usually it's better to use a lexical variable instead. $_ is global and can (accidentally) be manipulated by other code, especially code that someone else inserts later. You can use something like while (my $line = <$in>) { instead.

In reply to Re^2: How can I find a line in a RTF file? by Anonymous Monk
in thread How can I find a line in a RTF file? by kevyt

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.