foreach my $file(@array){
... get filenames ...
}
unless something liek this would have worked.
foreach my $file(@array){
get_filenames($file);
}
sub get filename{
my ($file) = @_;
foreach my $filename($file){ #get filename from file stored in @array
+ and find it.
... find file...;
copy_file($filename)
}
sub copy_file{
my ($filename ) = @_;
foreach ($filename)
copy($filename, "copied_files/$dest"); #this is the tricky part, which
+ i will try to describe <.<
See, the way the script works, is each of those files in in the temp folder, are how i rebuild the copied files directory. you could put a file called "HOTLANTA" in temp folder, and it would create a folder in copied files directory called "HOTLANTA". That was the only way i could think of to make it work like that. otherwise it just copied all the files to the root of the copied files folder (which is not what i wanted and is the reason i made a 700 line script lol. maybe i could have put a counter or something in there? or when reached EOF, i could have called the first sub again, i am not sure, but it absolutely depends on the array element to be able to copy the file back to the right folder. otherwise its just gonna copy all ove rthe place wont it?
I did make this to build my huge loops tho xD
open my $temp, '>', "loopfile"
;
my $num = "000";
my $dev_flash= '$dev_flash';
my $dev = '@dev_flash';
foreach (0 .. 27){
print $temp "if ($dev$num == 0){\nprint '';\n}else{\n",
'print "\n\n'," dev_flash$num",'\n',"|=============================
+=====>",'\n', '";', "\n",
'foreach my $filename(', "$dev$num", '){',"\n",
'print "\t$filename";', "\n", "\t",'}', "\n", '}', "\n\n";
+ "\n
+\n\tdev_flash018\n|==================================>\n", @dev_flash
+018;
$num0++;
}
my $num1 = 000;
foreach(0 .. 27){
print $temp 'elsif (', "$dev_flash$num1", '=~ /\b$file\b/i ){', "\n",
'if (-e "./copied_files/', "dev_flash$num1", '/$file"){', "\n",
#' print "$dir/$file match\n";', "\n",
' push ', "$dev$num1",',', '"$file\n";', "\n",
' my $des = "./copied_files/', "dev_flash$num1", '/duplicate/";', "
+\n",
' copy ("$dir/$file", $des) or die "$!";', "\n",
'}else{', "\n",
' push ', "$dev$num1",',', '"$file\n";', "\n",
' my $des = "copied_files/', "dev_flash$num1", '/";', "\n",
' copy ("$dir/$file", $des) or die "$!";', "\n",
'}', "\n",
'}', "\n";
$num1++;
}
that was tedious, but worth the effort. cz once i got this done i could make simple changes and update the original script easily. |