Skip to content

Instantly share code, notes, and snippets.

@burbridgeconsulting
Last active April 22, 2019 02:30
Show Gist options
  • Save burbridgeconsulting/83b1e32e9cbd5bfe9e1e91bd568a0cdf to your computer and use it in GitHub Desktop.
Save burbridgeconsulting/83b1e32e9cbd5bfe9e1e91bd568a0cdf to your computer and use it in GitHub Desktop.
Replace a URL in exported Beaver Builder template XML file
#!/usr/bin/perl
use strict;
my $search = 'http://old-url.com/';
my $replace = 'https://new-url.org/';
my $length_difference = length($search) - length($replace);
my $filename = "exported_bb_template.xml";
# my $filename = "/Users/christopherburbridge/Downloads/test.xml";
open(my $fh, $filename) or die "Could not open file '$filename' $!";
while (my $row = <$fh>) {
# chomp $row;
# print "$row\n";
$row =~ s/s:(\d+):"($search)/
's:' . ($1 - $length_difference) . ':"' . $replace
/xeg;
print $row;
}
@burbridgeconsulting
Copy link
Author

The only need for this, as opposed to just using a search and replace in a text editor, is that the number after the string directive in the serialized data needs to change, and each time would be different. In the case that I had, the $replacement string was shorter than the $search string. I presume it would work the other way too, but I have not tested that yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment