Link to home
Start Free TrialLog in
Avatar of erum87
erum87

asked on

Printing header just once ina a loop

Hi i have a script that should look like this-
###########################################################
Plan: the plan its accessing
Chapter: the chapter under that plan
Owner:Default owner (there can be multiple owners)
Platfrom: Default platform
Env : Default environemt

(milestone=1 , env= if its not the default env display the other env here)
#print files relevant to milestone 1 under that plan under that chapter
filename1
filename2
filename3
filename4
(milestone=2 , env= if its not the default env display the other env here)
filename5
filename6
filename7
(milestone=3 , env= if its not the default env display the other env here)
filename8
(milestone=4 , env= if its not the default env display the other env here)
filename9
filename10
filename11
filename12
filename13
filename14
#############################################################

but instead looks like

############################################################
Plan: the plan its accessing
Chapter: the chapter under that plan
Owner:Default owner (there can be multiple owners)
Platfrom: Default platform
Env : Default environemt

(milestone=1 , env= if its not the default env display the other env here)
#print files relevant to milestone 1 under that plan under that chapter
filename1
filename2
filename3
filename4

Plan: the plan its accessing
Chapter: the chapter under that plan
Owner:Default owner (there can be multiple owners)
Platfrom: Default platform
Env : Default environemt

(milestone=2 , env= if its not the default env display the other env here)
filename5
filename6
filename7

Plan: the plan its accessing
Chapter: the chapter under that plan
Owner:Default owner (there can be multiple owners)
Platfrom: Default platform
Env : Default environemt

(milestone=3 , env= if its not the default env display the other env here)
filename8

Plan: the plan its accessing
Chapter: the chapter under that plan
Owner:Default owner (there can be multiple owners)
Platfrom: Default platform
Env : Default environemt

(milestone=4 , env= if its not the default env display the other env here)
filename9
filename10
filename11
filename12
filename13
filename14
##############################################################

So the body of my code looks like this
##############################################################
my $flag = 0;
foreach $plan(@plan){
      foreach $chap(@chap){
            foreach $mlst (@milestone){
                  foreach $plt (@platform){
                  for (i=0;i<=200;i++ )
                  if (($some{$hash}{$of}{plan} eq $plan) && ($some{$hash}{$of}{chap} eq $chap)&&($some{$hash}{$of}{mlst} eq $mlst)&&($some{$hash}{$of}{plt} eq $plt))
{
if ($flag ==0){
print "Plan= $plan";
print "Chapter=$chap";
print "Owner=$owner"; #processed in a subroutine
print "Platform=$plt";
print "(Milestone = $mlst , env: $en)";
}
print "$some{$hash}{$of}{filename}";
$flag = 1;
} } }  } }...
###########################################################

Please help me fix it !!
Avatar of Amick
Amick
Flag of United States of America image

If I understand what you're trying to do this may work:

foreach $plan(@plan){
	print "Plan= $plan";
	foreach $chap(@chap){
		print "Chapter=$chap";
		print "Owner=$owner"; #processed in a subroutine
		print "Platform=$plt";
            foreach $mlst (@milestone){
		print "(Milestone = $mlst , env: $en)";
                  foreach $plt (@platform){
			  for (i=0;i<=200;i++ )
			  if (($some{$hash}{$of}{plan} eq $plan) && ($some{$hash}{$of}{chap} eq $chap)&&($some{$hash}{$of}{mlst} eq $mlst)&&($some{$hash}{$of}{plt} eq $plt))
				print "$some{$hash}{$of}{filename}";
			}
		}
	}
}

Open in new window

Avatar of erum87
erum87

ASKER

I'm sorry but it does not work :(

It prints the header for all the iterations its going through. And i just want it printed once at the top for that particular values relevant to those elements in the loop.
ASKER CERTIFIED SOLUTION
Avatar of Amick
Amick
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial