Last active
August 29, 2015 14:21
-
-
Save NGTOne/9d8148b4de0a2e52170f to your computer and use it in GitHub Desktop.
A script to indicate issues with .craft files
This file contains 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/local/bin/perl | |
use strict; | |
use warnings; | |
open(my $fh, '<:encoding(UTF-8)', $ARGV[0]) | |
or die "Could not open craft file $ARGV[0]"; | |
my (@parts, @links, @line); | |
my $index = 0; | |
foreach(<$fh>) { | |
$index++; | |
if (/part =/) { | |
@line = split '_'; | |
} elsif (/partName =/) { | |
push(@parts, {lineNumber => $index, partID => $line[1], partType => (split ' = ')[1]}); | |
} elsif (/link =/) { | |
push(@links, {lineNumber => $index, partID => (split '_')[1], partType => 'link', good => 0}); | |
} | |
} close $fh; | |
foreach (@links) { | |
for (my $i = 0; $i < @parts && %$_{good} == 0; $i++) { | |
if ($parts[$i]->{partID} == %$_{partID}) { | |
$_->{good} = 1; | |
} | |
} | |
if (!%$_{good}) { | |
print "Unlinked part found at line $_->{lineNumber}.\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment