Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hello All,
This might be a very round about question to pose but the tag line of PERL monks says stupid most question is question not asked!! I have a code where I am matching lines in if else block. If the line matches to the pattern in the if block it performs some task. Same is for elsif blocks too. Finally if the line does not match to any of these it sends it to else block printing it as error. I want to know exactly where the pattern did not match the given line in the loop. Is there any efficient and less costly way to find this?
if($a=~/ABC\s+XYZ/){ #do something }elsif($a=~/PQR\s+LMN/){ #do something }else{ print "Error\n"; #Want to know where exactly did the regex in above checks failed OR ne +ed to tell the user that your query failed at this particular place. }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to find where regex did not match across the line
by moritz (Cardinal) on Mar 12, 2012 at 13:47 UTC | |
by Anonymous Monk on Mar 13, 2012 at 04:40 UTC | |
|
Re: How to find where regex did not match across the line
by LanX (Saint) on Mar 12, 2012 at 16:46 UTC | |
|
Re: How to find where regex did not match across the line
by ww (Archbishop) on Mar 12, 2012 at 15:27 UTC | |
by tye (Sage) on Mar 12, 2012 at 20:10 UTC | |
by ww (Archbishop) on Mar 12, 2012 at 21:34 UTC | |
|
Re: How to find where regex did not match across the line
by Marshall (Canon) on Mar 12, 2012 at 16:20 UTC |