http://www.perlmonks.org?node_id=815659


in reply to Programmatically Updating Code with PPI

I don't have PPI installed, so can't test; but I hope you don't mind a few quick questions:
  1. Wouldn't
    my $lexicon = $doc->find(sub { $_[1]->content eq '%Lexicon' }); $lexicon = $lexicon->[0]; # returns an array ref, but in my case, ther +e's only ever one.
    be better as
    my $lexicon = $doc->find_first( ... )
    ?
  2. Does the insert_after call return true?
  3. When $lexicon is returned by find, is it still “part of” $doc? That is, could it be that you're modifying only $lexicon, not $doc?