Esteemed Monks,

I am working on another script that makes changes to postscript files. This time I am trying to delete lines that ask for paper types that aren't going to be used in the document. My sub takes the current line and a list of media types to remove.

Here's my sub and the sample data I copied out of a larger file for testing.
sub kill_media { my $line = shift; my $media; if ($line =~ m!^%%DocumentMedia:!){ $media_killed=1; print OUT $line; while ($line = <IN>){ foreach $media (@_) { if ($line =~ m!$media!){ $line = ""; print "Killed media type: $media\n"; } elsif ($line !~ m!^%%+!){ return $line; } } print OUT $line; } } ----SAMPLE DATA----- %XRXbegin: 001.014 %XRXtitle: JOB P04063001.X0026 - Wps %XRXsenderName: CompuSet %XRXdisposition: PRINT %XRXcopyCount: 1 %XRXrequirements: duplex %XRXsignature: False %XRXorientation: Portrait %XRXxImageShift: 0 %XRXyImageShift: 0 %XRXend %!PS-Adobe-3.0 %%DocumentMedia: anything 612 792 0 white () %%+ anything 612 792 0 blue () %%+ anything 612 792 0 green () %%+ anything 612 792 0 pinky () %%+ anything 612 792 0 UNIVERSALID () %%Creator: CompuSet Version 8.0.0 %%CreationDate: 3/03/2004 16:04:28 %KDKHost: Binder %%BoundingBox: 0 0 612 792 %%Pages: 182


I want to kill the pinky and UNIVERSALID media calls. The strange thing is the line for UNIVERSALID doesn't get deleted when it is the last one. If I swap the pinky and UNIVERSALID lines, both get deleted correctly. This isn't making any sense to me, so I am seeking the wisdom of the monks.

digger

In reply to Simple regex gone wierd by digger

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.