in reply to Re: Calculations in Regexp
in thread Calculations in Regexp

Thanks for your answers!

I am working on a large text file and putting markers around data and was trying to find out efficient ways.

I have finally decided to use:
 
while($data=~<BEGIN_FLAG>) {$count++;}
 
Thank you!

Replies are listed 'Best First'.
Re^3: Calculations in Regexp
by jethro (Monsignor) on Jan 20, 2011 at 16:49 UTC

    Don't forget the g modifier or this will be an endless loop. And don't forget the slashes or this won't even be a regex

Re^3: Calculations in Regexp
by locked_user sundialsvc4 (Abbot) on Jan 20, 2011 at 15:19 UTC

    If that is what you call “efficiency,” you are barking up the wrong tree for the wrong reasons.   No matter how “large” your text file may be, the CPU will spend the vast majority of its wall-time waiting for I/O.   It will spend an insignificant amount of time incrementing a variable, or even schlepping text around in memory (as long as virtual-storage paging is not “sneaking-in a significant amount of hidden I/O”).

    What is a valid engineering concern, however, is just how easy it will continue to be to understand and to maintain your code in the future ... long after you have been smooshed (oops... hate it when that happens) by that most unfortunate bread truck.   Will your “clever trick” seem quite so clever when it turns into a bug?   Food for thought, and offered in that constructive spirit.