A somewhat different approach to the problem--it strikes a balance between slurping the file and processing it line by line--setting $/ as a 'boundary marker' and using -n to take care of the file handling. You just attach your code at the bottom and process the %ids hash as you need to.
Caveats: It doesn't validate the format of the input file by cross-checking the end of block with the start. Testing is minimal in the absence of more information regarding the file format/content, and there are too many possible variations to try and guess.
#! perl -nslw use vars qw[%ids]; use strict; BEGIN{$/="\nchecking";} if ( m[<(NT-Development_\d{10}_FULL)>.*?(media does not exist)?\Z] +s ) { $ids{$1} = defined $2 ? 'missing' : 'ok'; } }{ #! terminate implied (perl -n) while loop and start continue block #! process hash here. print "$_ was $ids{$_}" for sort keys %ids;
sample usage
7:59:54.25 C:\test>type junk the quick brown fox jumps over the lazy dog the quick brown fox jumps +over the lazy dog checking image file <NT-Development_1024371283_FULL> >copy 1 frag 1 media CC0202 host netbackup2: media does not exist >copy 1 frag 2 media CC0202 host netbackup2: media does not exist >copy 1 frag 3 media CC0202 host netbackup2: media does not exist >copy 1 frag 4 media CC0202 host netbackup2: media does not exist >copy 1 frag 5 media CC0202 host netbackup2: media does not exist checking files file <NT-Development_1024371283_FULL.f> the quick brown fox jumps over the lazy dog the quick brown fox jumps +over the lazy dog the quick brown fox jumps over the lazy dog the quick brown fox jumps +over the lazy dog checking image file <NT-Development_1024371284_FULL> >copy 1 frag 5 media CC0202 host netbackup2: checking files file <NT-Development_1024371284_FULL.f> the quick brown fox jumps over the lazy dog the quick brown fox jumps +over the lazy dog Sir! The pedants are regrouping. Sir! The pedants are regrouping. the quick brown fox jumps over the lazy dog the quick brown fox jumps +over the lazy dog checking image file <NT-Development_1024371285_FULL> >copy 1 frag 1 media CC0202 host netbackup2: media does not exist >copy 1 frag 5 media CC0202 host netbackup2: media does not exist checking files file <NT-Development_1024371285_FULL.f> the quick brown fox jumps over the lazy dog the quick brown fox jumps +over the lazy dog 7:59:59.93 C:\test>test junk NT-Development_1024371283_FULL was missing NT-Development_1024371284_FULL was ok NT-Development_1024371285_FULL was missing
Examine what is said, not who speaks.
The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.
In reply to Re: How to act upon lines between two other lines in file?
by BrowserUk
in thread How to act upon lines between two other lines in file?
by blink
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |