need to remove strings from a huge scripe made of thousands of the following :
------ Rebuild All started: Project: Types, Configuration: Debug .NET
------
Preparing resources...
Updating references...
Performing main compilation...
Build complete -- 0 errors, 0 warnings
Building satellite assemblies...
Need it to identify the start say "----- Rebuild" and the end say "assemblies"
Want to copy the code (after testing the 0 errors part) to a new file say "errorlog.txt" to reduce the time it takes to find all the indivual failings
so, in this make-believe situation below, you would want to remove the highlighted red block and write to 'errorlog.txt' and keep the rest of the text as it is
text
more text
even more text
[red]------ Rebuild All started: Project: Types, Configuration: Debug .NET
------
Preparing resources...
Updating references...
Performing main compilation...
Build complete -- 0 errors, 0 warnings
Building satellite assemblies...[/red]
it works through the file, line by line, outputting all the lines to 'errorlog.txt' until it sees Rebuild All started. then it outputs the text to the screen until it sees Building satellite assemblies then it reverts back to 'errorlog.txt' again. a kind of switch.
open (INFILE, "<file.txt"
open (ERRORLOG, ">errorlog.txt"
select ERRORLOG;
while (<INFILE>) {
if (/Rebuild All started/) { select STDOUT; }
print "$_";
if (/Building satellite assemblies/) { select ERRORLOG; }
the $/ = undef; will read in the whole file in one go. this gets round the problem of having to wait until getting to the error line to find '0 errors' - then all that has been written is in vain! raklet's regex can then search through all of the necessary lines before deciding to write to the file or not
That is a nice compliment from someone that I look up to as a mentor on this forum. Perl is my first programming language and I have only been at it for 3-4 months.
Blimey! - Very kind words. I don't consider myself as adept as you at this Perl scripting! Only 3-4 months... You're doing an amazing job... keep it up!!!
Not to br one to complain but all this does is make an exact copy of the INFILE ever time. Maybe Im not helping amidst all the confusion : I dont want to copy the entire file if there is errors just the sections which contain errors. So if a section between one of the "Rebuild All started.+Building satellite assemblies" contains an error it is added to the "errorlog.txt" file otherwise it skips to the next "Rebuild All started.+Building satellite assemblies". The script should then at the end reduce 26 pages or more down to just the one or two pieces which contain errors.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.