Re: Was `readdir [...]' Comments on JK's script



On Monday 03 December 2007 18:00, reader@xxxxxxxxxxx wrote:

John W.Krahn <krahnj@xxxxxxxxx> writes:

I thought it might be because File::Find cds to the target dir
then names like src dir or ./src ./dir fail. Just guessing

OK, that's my mistake, as I said I didn't test it ... oops. :-)

I guess you knew this from your smilie but to confirm ... that was
not a complaint...I really appreciate getting a look at well done
code. I've wallowed around with my own pathetic code for years really
without really paying attention to how it should be done. I'm a home
user who likes to script up stuff at times. Fortunately no one else
suffers from poor coding. (Except usenet.. and mailing lists.. hehe)

I do have another related question about this whole thing.
Originally (not in the code I posted)
I wanted to make the script so it could either copy the files or just
report on the findings (file name and content of regex that hit).

I used a getopts to make the decision and when copying wasn't
selected I thougt it would be smart to break out of the while loop
inside a find() either when the regex hit, or when the first blank
line showed up, which ever came first.

Some of the directories I'm working with are pretty big. The biggest
one is over 400,000 posts. So reading only up to the regex hit would
represent quite a lot of lines saved.

The regex are only aimed at headers. Most often From: or Subject:.

I was reading lines with a while loop inside find() so used a `last'
to break out of it. Perl gives a warning for that so I thought maybe
it wasn't such a good idea... but finally resorted to sticking with
the last and quieting the warnings with `no warnings' locally.

Perl will not warn when using 'last' (or 'next' or 'redo') inside a
while loop so either you used it outside the loop or you used it with
the while statement modifier.


So two questions:

1) With the scale of data I'm talking about would breaking out after
finding the regex be of much benefit. (when not copying)

Probably yes.


2) What is the best way to break out of a while loop early, inside a
find()?

If you need to process stuff after the loop ends use 'last' to exit the
loop.


John
--
use Perl;
program
fulfillment
.



Relevant Pages

  • Re: Was `readdir [...] Comments on JKs script
    ... report on the findings (file name and content of regex that hit). ... So reading only up to the regex hit would ... I was reading lines with a while loop inside findso used a `last' ... the last and quieting the warnings with `no warnings' locally. ...
    (perl.beginners)
  • Re: Stupid Mistakes
    ... before the loop. ... ...oh, I see, it's a global set by findswfile. ... when you come back to this in six months' time) some searching. ... is a special character in a regex, ...
    (comp.lang.perl.misc)
  • RE: Reading contents of file
    ... keep the regex match as it is i.e. while ... But inside the loop when you a find a match and do relevant things, ... the existence of the matched pattern which is done by the help of bookref ... When I run the following script it goes to unending because it is ...
    (perl.beginners)
  • RE: Reading contents of file
    ... 2)I am not able to print the unmatched data i.e in the above example '45' doesn't match the regex in the while loop so this cannot be printed in the output file. ... the existence of the matched pattern which is done by the help of bookref ...
    (perl.beginners)
  • Re: Slow performance after Conversion C# application to VS 2005
    ... If I take the Regex variable declaration and instantiation out of the ... If I leave it in the loop but don't assign count by commenting the last ... line it also takes around 300 milliseconds. ... so we are not losing time if we ...
    (microsoft.public.dotnet.framework)