There are two directories(for eg. alpha and gamma), which contain numerous xml files . each xml file in alpha corresponds to a file in gamma directory . The naming convention of these two files in two directories have a pattern for eg
File in alpha -> abc_12342_tick.xml.alphaprodFile in gamma -> abc_12342_tick.xml.gammatest
What I am trying to achieve is a hash with these file names paired. here is what I did. @alphafiles and @gammafiles contains the file list from alpha and gamma directory.
This code works fine for a smaller set of files in these directories but for a large set of files the number of iterations increases and it becomes extremely slow like takes 90 mins to pair up 30000 files in each directory. I also tried a simpler approach of sorting @alphafiles and @gammafiles lists first and then pairing them like below@hash{@alphafiles}=(); foreach (keys %hash){ my $patt=substr($_,0,index($_,"xml")); @matched=grep(/^$patt/,@gammafiles); $hash{$_} = $matched[0]; }
This method takes hardly a couple of minutes but I doubt the reliability of this approach.I need to make sure I pair the correct files from the two directories.I seek your wisdom. Is there a way to apply a regex during sorting of the arrays which yields files at the correct positions before clubbing?@sortalpha= sort @alphafiles; @sortgamma= sort @gammafiles; $i=0; while($i <= $#sortprod) { $hash{$sortalpha[$i]}=$sortgamma[$i]; $i++; }
Thanks in advance
'When You starve With A Tiger, The Tiger always starves last'
In reply to File pairing from different directories by Zoop
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |