(Edit: See perrin's answer; his way is MUCH cleaner)

The problem is your slurp of all the lines in your join, I think. -i only works right if it can match up your print to the file currently being read, and your <> slurped up all the files.

I _think_ this may work better for you (untested!):

perl -i.bak -ne'if($f ne $ARGV[0]){if(defined($f)){print "prepend\n",@ +lines,"append\n"; @lines=();} $f=$ARGV[0]} push @lines,$_;' *.html */ +*.html */*/*.html */*/*/*.html
It's alway safer to use .bak on your -i, in case of disasters like the one you mentioned in your post.

If it all worked, it's easy to get rid of the .bak files.

You might also want to think about using find | xargs instead of the nested directory wildcards; it's probably going to work more efficiently, and it won't croak on a huge directory tree.
--
Mike


In reply to Re: In-place header/footer by RMGir
in thread In-place header/footer by swiftone

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.