in reply to Re: Extracting string from a file
in thread Extracting string from a file

I have a problem with your regex /^.\|TOTAL.*$/i, more specifically with the .*$ part of it.

That part actually says "anything (even nothing) until the end of the string" and is therefore superfluous.

Worse is that /^.\|TOTAL.*$/i will allow to pass a line without any digits in it and therefore will push nothing on the @dump array but neither is the $false_count variable incremented. Of course it is very well possible that the file will always have digits on its "TOTAL" lines, but IMHO that is a dangerous assumption to make.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics

Replies are listed 'Best First'.
Re^3: Extracting string from a file
by builat (Monk) on Nov 13, 2013 at 14:27 UTC
    You are absolutely right. And yes I really started from the premise that any string beginning with ~ | TOTAL further contains a set of numbers. It would be better to add a check for the presence of numbers on the right side of expression. Thank you.