in reply to Re^4: Multiple command prints in same output file
in thread Multiple command prints in same output file

ok.. i get it now .. so what you're doing is looping through and for each record your tacking via string concatenation stuff onto several different variables ( $CreateViewCmd, D, ChangeDirectory, LoadViewCmd, Pause ). Then just printing those "once" (well, multiple times but file gets clobbered each time) at the end -- that's why the "like" commands are grouped together.

so .. how to go about fixing this -- basic approach is that the order needs to be maintained .. e.g. the LoadViewCmd stuff for row 3 has to come before the ChangeDirectory stuff for row 2.

One way (quickest to code) to this would be to print LOADCREATE $somestring as you go..

Another way would be to save those variables for each datarow so they stay together w/in the datarow.
my @rows; foreach (){ # for a data row my %row = ( map { $_ => '' } qw/CreateView Cmd D ChangeDirectory Loa +dView Pause/ ); # do your stuff, but change stuff like: $Pause .= "foo\n"; # to: $row{Pause} .= "foo\n"; # --> note scoping issues .. you probably want to pass around a refe +rence to %row push @rows, \%row; } # and not print everything at the end... open LOADCREATE, ...; foreach my $row (@rows){ print LOADCREATE $row-{CreateViewCmd}; print LOADCREATE $row->{D}; print LOADCREATE $row->{ChangeDirectory}; print LOADCREATE $row->{LoadViewCmd}; print LOADCREATE ${Pause}; } close LOADCREATE;