Advertisement

10.18.2005 at 04:56PM PDT, ID: 21599655
[x]
Attachment Details

Nested Foreach Loops

Asked by ts01206 in Perl Programming Language

Tags: nested, foreach, perl

The following code, as I'm sure one of you experts will know, is not executing as expected:

foreach (@cpus) {
   $cpu = $_;
   foreach (@prefixes) {
       $prefix = $_;
   }
  `composer "cr $prefix$ssuffix from sched=$cpu#@"`;
  `composer "cr $prefix$jsuffix from jobs=$cpu#@"`;
}

@cpus and @prefixes contain different values.  What I was expecting to receive was the creation of two files for each $cpu, each beginning with the $prefix value from the @prefixes array and then ending with values of $ssuffix and $jsuffix as defined earlier in the script and then as derived from the "from" part of the composer line.  As an FYI, composer is another program (non-perl and vendor written) that I'm executing to pull definitions from a database.  Instead, what I wind up with is just the last two files from the last $cpu value.  In short, it appears I'm over writing the files each iteration through and I'm not looping as expected.

Any and all help will be appreciated.  Thanks in advance.Start Free Trial
[+][-]10.18.2005 at 04:59PM PDT, ID: 15112589

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.18.2005 at 05:00PM PDT, ID: 15112593

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.18.2005 at 05:18PM PDT, ID: 15112668

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.18.2005 at 05:32PM PDT, ID: 15112726

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.18.2005 at 05:58PM PDT, ID: 15112808

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]10.19.2005 at 06:47AM PDT, ID: 15115775

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.19.2005 at 12:38PM PDT, ID: 15119097

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.19.2005 at 01:04PM PDT, ID: 15119323

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Tags: nested, foreach, perl
Sign Up Now!
Solution Provided By: kamermans
Participating Experts: 3
Solution Grade: A
 
 
[+][-]11.07.2005 at 09:21AM PST, ID: 15240618

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32