#!/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); &copySelected(\@branchesSelected); 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); } } # shows results for foreach loops when separated foreach my $branches (@selectedBranches) { mi0::LogManager::info("branches copied: $branches"); } foreach my $files (@selectedFiles) { mi0::LogManager::info("files copied: $files"); } # no values from variables $files and $branches when combined foreach my $branches (@selectedBranches) { mi0::LogManager::info("branches copied: $branches"); + foreach my $files (@selectedFiles) { mi0::LogManager::info("files copied: $files"); } } }

combined foreach loop gives no values, but when foreach loops are separated (seen above) I get values

foreach my $branches (@selectedBranches) { mi0::LogManager::info("branches copied: $branches"); + foreach my $files (@selectedFiles) { mi0::LogManager::info("files copied: $files"); } }

I'm trying to get values for combined foreach loops

I also tried sending values to another subroutine but got the same results

Thanks for your help


In reply to Not getting values from combined foreach loops by begood321

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.