Created
July 13, 2011 16:19
-
-
Save dbb/1080666 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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