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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.