Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

can it be perl teim?

Name: Anonymous 2010-04-15 22:18

Hey, /prog/. Here's a script to autosort your anime into folders. You can thank me later.

#!/usr/bin/perl

use strict;
use warnings;

use File::Copy;

my @files = glob "*.mkv *.avi *.mp4";

foreach (@files) {
    my $file = $_;
    $_ =~ s/\ /_/g;

    print "$file\n";

    my @data = ($_ =~ m/^[([^[\]]+)\]([^[\]]+).+$/);
    next unless($data[1]);

    my $anime = ($data[1] =~ m/^((.*?)\d{2,3})/)[1];
   
    unless($anime) {
        $anime = ($data[1] =~ m/^(.+)$/)[0];
    }

    $anime =~ s/\./_/g;

    if ($anime =~ m/\-_$/) {
        $anime =~ s/\-_//g;
        $anime =~ s/_/\ /g;
        $anime =~ s/^\s+//;
        $anime =~ s/\s+$//;
    } else {
        $anime =~ s/_/\ /g;
        $anime =~ s/^\s+//;
        $anime =~ s/\s+$//;
    }

    unless (-d $anime) {
        next unless(mkdir $anime);
    }

    move("$file", "$anime/$file");
}

exit 0;

Name: Anonymous 2010-04-16 0:54

>>15
I happen to know you didn't even try.

>>16
Same goes for the rest of my comment. :/

>>17
There's something you can do. OP's code could have broken things down more clearly with roughly the same reliance on regex. It's pointless though, and far better to use only about half as much regex (and still reduce the amount of supporting code needed.)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List