Thanks Choroba for your reply, I agree it should have worked, which is strange. However, I found a way to get it work, here is solution below. I think the problem was the subroutine call from the previous code, which I removed and modified the foreach loop in complete code as seen below.
#removed from current code
copySelected(\@branchesSelected);
#complete solution below
#!/web/soft/iw-home/TeamSite/iw-perl/bin/iwperl
use strict; # require variables to be declared
use diagnostics; # expand warnings (-w) expanation
use File::Find;
my @branchesSelected = qw(test_branch);
my %options = (preprocess =>\&new_dir, wanted=>\&wanted);
find ( \%options, @root);
######################################################################
+###
# process files per directory
######################################################################
+###
sub new_dir
{
my @files = @_; # the readdir() output
# contains both (files and directories)
# find html files under pages directory
if ($File::Find::dir =~ m|pages|) {
# sort files
@files = sort(@files);
# process files and directories
foreach my $name (@files) {
next if ($name !~ m|workshop|);
# scan files
if (-e $name) {
# skipped if not html file
next if ($name !~ m|\.html$|);
push (@copyFiles, "$File::Find::dir/$name");
}
elsif (-d $name){
mi0::LogManager::info("Directory found $name, cannot c
+opy folders");
}
else{
mi0::LogManager::info("No Files found");
}
copySelected(\@copyFiles);
mi0::LogManager::info("");
}
}
return @files; #return the list to continue processing
} # End of sub new_dir {
######################################################################
+###
# needed for syntax, extra's for getting size etc. if needed
######################################################################
+###
sub wanted
{
# not used here, but dummy sub is needed for syntax
# this routine is called for each file/directory
# if we wanted to do something special for each one
# maybe get a size or whatever...
# the full path name of this file would be in $File::Find::name
} # End of sub wanted {
sub copySelected ($) {
my $copy_selected = $_[0];
my @selectedBranches = qw();
my @selectedFiles = qw();
foreach my $selected (@$copy_selected) {
next if $duplicates { $selected }++;
if ($selected =~ m|\/|g) {
mi0::LogManager::info("files selected: $selected");
push(@selectedFiles,$selected);
} else {
mi0::LogManager::info("branches selected: $selected");
push(@selectedBranches,$selected);
}
}
#solution
foreach my $branches (@branchesSelected) {
mi0::LogManager::info("branches selected: $branches") if !$dup
+licates { $branches }++;
foreach my $files (@selectedFiles) {
$files =~ s|$copyFromBranch|$branches|g;
mi0::LogManager::info("files copied: $files");
}
}
}
|