Skip to content

Instantly share code, notes, and snippets.

@dbb
Created July 13, 2011 16:19
Show Gist options
  • Save dbb/1080666 to your computer and use it in GitHub Desktop.
Save dbb/1080666 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use 5.010;
use strict;
use warnings;
my $pattern = '<!-- placeholder -->';
my $text = << "EOF";
<html>
<head>
<title>foo</title>
</head>
<body>
<p>Some text.</p>
<!-- placeholder -->
<p>More text</p>
</body>
</html>
EOF
say "# Before #############################\n$text";
my $replacement = '<a href="foo">bar</a>';
my @lines = split "\n", $text;
say "# After #############################\n";
for ( @lines ) {
s/$pattern/${replacement}\n$pattern/g;
say;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment