Skip to content

Instantly share code, notes, and snippets.

@johannes-riecken
Created August 2, 2017 03:11
Show Gist options
  • Save johannes-riecken/a28cb275f3209478253939decf9c2e31 to your computer and use it in GitHub Desktop.
Save johannes-riecken/a28cb275f3209478253939decf9c2e31 to your computer and use it in GitHub Desktop.
use v5.10;
use warnings;
use Data::Dumper;
my %h;
sub wrap {
my ($str, $re,$replace) = @_;
unless (%h) {
END {say Dumper %h}
}
$h{$re} += $str =~ s/$re/$replace/;
return $str;
}
my @lines = qw(foo bar baz);
for (@lines) {
$_ = wrap($_, qr{foo}, 'lorem');
$_ = wrap($_, qr{bazzz}, 'ipsum');
}
say Dumper @lines;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment