in reply to help with conditional match?

Just remember whether you've encountered "***Private-from-iPhone***" (say in some variable $is_private), and only add the line in this case:

... my $is_private = 0; while (<>) { $is_private = 0 if eof; # reset chomp; if (/\Q***Private-from-iPhone***/) { $is_private = 1; } # print additional line if ($is_private && /SUMMARY:/) { s/$/\nX-CALENDARSERVER-ACCESS:CONFIDENTIAL^M/; } print "$_\n"; } ...

(This assumes that DESCRIPTION: occurs before SUMMARY:, of course)

Update: added # reset line, as per GrandFather's/moritz's note — (I had overlooked that the script is supposed to process multiple files in one go).

Replies are listed 'Best First'.
Re^2: help with conditional match?
by GrandFather (Saint) on Mar 04, 2009 at 23:42 UTC

    If a list of files may be handed in on the command line then $is_private should probably be reset when the additional line is inserted.


    True laziness is hard work