Created
May 31, 2021 08:20
-
-
Save trapd00r/e87f15dc3dc449c9c1f65d834998d77b to your computer and use it in GitHub Desktop.
delete $file with a suffix if $file with other suffix exists
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 | |
# vim: ft=perl:fdm=marker:fmr=#<,#>:fen:et:sw=2: | |
# abstract: delete $file with a suffix if $file with other suffix exists | |
use strict; | |
use warnings FATAL => 'all'; | |
use vars qw($VERSION); | |
use autodie qw(:all); | |
use utf8; | |
use open qw(:std :utf8); | |
use File::Basename; | |
my @files = glob('*'); | |
my @mods; | |
for my $f(@files) { | |
my($filename, undef, $suffix) = fileparse($f, qr/[.][^.]*/); | |
if($suffix !~ m/\.mp3/i) { | |
push(@mods, "$filename$suffix"); | |
if(-f "$filename.mp3") { | |
unlink "$filename.mp3" or warn "Could not unlink $filename.mp3: $!" | |
} | |
} | |
} | |
__DATA__ | |
.ahx | |
.bp | |
.fc14 | |
.it | |
.mid | |
.MID | |
.mo3 | |
.mod | |
.ogg | |
.s3m | |
.sc68 | |
.v2m | |
.wav | |
.xm | |
.ym |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment