#!/usr/bin/perl #check cube structures #same alias in 2 different dimensions, it picks the wrong dimension (last dimension:alias overwrites previous dimension) use strict; my $tm1aliases = "D:\\alias.dictionary.csv"; my $tm1cubes = "D:\\cubes.csv"; my $tm1path = "D:\\tm1data"; ################# my %dictionary; my %cube; #load cubes structures open FD, $tm1cubes or die "Cannot access $tm1cubes\n"; while() { my ($c,$dimension) = split /,/; chomp($dimension); $cube{$c}{$dimension} = 1; #print "$c $dimension $cube{$c}{$dimension}\n"; #print "$cube{\"Aged Stock\"}{\"Branch\"}"; #might be ambiguous } close FD; print "cubes info loaded\n"; #load dictionary open FD, $tm1aliases or die "Cannot access $tm1aliases\n"; while() { my ($dimension,$attribute,$alias) = split /,/; chomp($alias); if($dictionary{"$alias"} ne "") { #append previous dimensions $dictionary{"$alias"} = ":$dimension:$dictionary{\"$alias\"}"; } else { $dictionary{"$alias"} = $dimension; } } close FD; print keys(%dictionary)." aliases loaded\n"; #seek & destroy opendir THISDIR, $tm1path or die "Cannot open $tm1path $!"; while (my $thisfile = readdir THISDIR) { if ($thisfile =~ /(.*)\.rux$/i) { my $c = $1; open(FLH, "$tm1path/$thisfile"); print "################## $thisfile\n"; my $line = 0; while () { $line++; #it is assumed the developer is not vicious enough to insert a line return in the middle of an element name #so all opening single-quote should match a closing single-quote on the same line foreach my $element (/'([^']*)'/gm) { my $dimension = $dictionary{$element}; my $dimension1 = $dimension; my $dimension2 = $dimension; #assuming there will not be more than 2 dimensions with identical aliases if ($dimension =~ m/:(\w+):(\w+)/) { $dimension1 = $1; $dimension2 = $2; #print "$dimension1 : $dimension2\n"; $dimension = $dimension2; $dimension = $dimension1 if ($cube{"$c"}{$dimension1} > 0); } if( $dictionary{$element} ne "" & $element ne "" & ($cube{"$c"}{$dimension} > 0) ) { chomp($_); print "line $line $dimension:$element in $_\n"; } } } close FLH; } }