Skip to content

Instantly share code, notes, and snippets.

@ology
Last active April 22, 2023 16:02
Show Gist options
  • Save ology/537402e7db5089f59e3c7955b21ddc02 to your computer and use it in GitHub Desktop.
Save ology/537402e7db5089f59e3c7955b21ddc02 to your computer and use it in GitHub Desktop.
Remove DOM element conditionally
#!/usr/bin/env perl
use strict;
use warnings;
use Mojo::DOM ();
use Mojo::File ();
my $xml_file = shift || die "Missing XML file\n";
my $path = Mojo::File->new($xml_file);
my $dom = Mojo::DOM->new($path->slurp);
$dom->find('g')->each(sub {
$_->remove if $_->{id} =~ /^path11[0-9]{3}$/;
});
print $dom;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment