ww has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regex error puzzle
by ikegami (Patriarch) on May 09, 2006 at 17:49 UTC | |
|
Re: regex error puzzle
by bmann (Priest) on May 09, 2006 at 17:48 UTC | |
by tye (Sage) on May 09, 2006 at 17:53 UTC |