Last active
April 22, 2019 02:30
-
-
Save burbridgeconsulting/83b1e32e9cbd5bfe9e1e91bd568a0cdf to your computer and use it in GitHub Desktop.
Replace a URL in exported Beaver Builder template XML file
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 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.