Skip to content

Instantly share code, notes, and snippets.

@NGTOne
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NGTOne/9d8148b4de0a2e52170f to your computer and use it in GitHub Desktop.
Save NGTOne/9d8148b4de0a2e52170f to your computer and use it in GitHub Desktop.
A script to indicate issues with .craft files
#!/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