update, ca 5 mins after posting: bmann posted correct answer just about same time as tye was helping me see my error on the cb. Thanks all! (solution: s/\Q$delete_candidate\E//)

This started out as demo-answer to a node now-deleted (because it was near identical dupe of another, [id://#548211], which has data slightly different).

But then, ka-ching!, AS 5.8.6 on W2K spat an error I did not expect, to wit: "Quantifier follows nothing in regex; marked by <-- HERE in m/* <-- HERE ...

Well, as you can see in code below, that's not exactly what's in the regex, but it's sorta' close to what's in line 7. BTW: data in this code is as OP posted, except this has more lines and varying years.

#! /usr/bin/perl -w use strict; use vars qw ( $string_in_file $delete_candidate @data_out $data_out ); foreach (<DATA> ) { $string_in_file = $_; # get the latest line from the file to the v +ar if ( $string_in_file =~ /^(\*{4}200[^6].*)$/ ) { # Quantifier follows nothing in regex; marked by <-- HERE in m/* <- +- HERE $delete_candidate = $1; s/$delete_candidate//; } else { push @data_out, $string_in_file; } } for $data_out(@data_out) { print $data_out; } __DATA__ ****2000-01-01****test1*****12345***** ****2001-01-01****test1*****12345***** ****2002-01-01****test1*****12345***** ****2003-01-01****test1*****12345***** ****2004-11-19****test1*****12345***** ****2005-07-01****test1*****12345***** ****2006-05-09****test1*****12345*****

the asterisk appears to me to be properly escaped; AFICT, Mastering Regular Expressions supports that...

So does this occur in other distributions? I doubt AS cares about correcting an older v. unless this is generic... and then only if I haven't contributed an error of my own that explains this.

CAUTION: see bmann below. full error message - to which I should have paid more careful heed - correctly IDed error line thusly: ... at date_elim.pl line 10, <DATA> line 7. <DATA> line 7; not code line 7.
AND see ikegami's re the other badness of the code above... His points are generally well-taken -- esp re my illogic in "throwing away $_" when my intent was to show the other poster that the first regex was a straightforward way to solve his problem.


In reply to regex error puzzle by ww

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.