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

This is what I expect:

cleartool mkview -snapshot -tag ASTest_Project_Integration_Snapshot -s +tream ASTest_Project_Integration@\PVOB_Test -colocated_server -host i +detestcc1 -hpath d:\ClearCase_Storage\views\snapshot\ASTest_Project_I +ntegration_Snapshot -gpath d:\ClearCase_Storage\views\snapshot\ASTest +_Project_Integration_Snapshot \\idetestcc1\ccstg_d\views\snapshot\AST +est_Project_Integration_Snapshot cleartool mkview -snapshot -tag Test_Johan_Integration_Snapshot -strea +m Test_Johan_Integration@\PVOB_Test -colocated_server -host idetestcc +1 -hpath d:\ClearCase_Storage\views\snapshot\Test_Johan_Integration_S +napshot -gpath d:\ClearCase_Storage\views\snapshot\Test_Johan_Integra +tion_Snapshot \\idetestcc1\ccstg_d\views\snapshot\Test_Johan_Integrat +ion_Snapshot cleartool mkview -snapshot -tag 1000_test_snapshot_Int_Snapshot -strea +m 1000_test_snapshot_Int@\PVOB_Test -colocated_server -host idetestcc +1 -hpath d:\ClearCase_Storage\views\snapshot\1000_test_snapshot_Int_S +napshot -gpath d:\ClearCase_Storage\views\snapshot\1000_test_snapshot +_Int_Snapshot \\idetestcc1\ccstg_d\views\snapshot\1000_test_snapshot_ +Int_Snapshot d: d: d: cd clearcase_storage\views\snapshot\1000_test_snapshot_Int_Snapshot cd clearcase_storage\views\snapshot\1000_test_snapshot_Int_Snapshot cd clearcase_storage\views\snapshot\1000_test_snapshot_Int_Snapshot cleartool update -add_loadrules .\InnovComp2\PRJ_1000_test_snapshot cleartool update -add_loadrules .\InnovComp2\PRJ_1000_test_snapshot cleartool update -add_loadrules .\InnovComp2\PRJ_1000_test_snapshot

This is what I would like to see:

cleartool mkview -snapshot -tag ASTest_Project_Integration_Snapshot -s +tream ASTest_Project_Integration@\PVOB_Test -colocated_server -host i +detestcc1 -hpath d:\ClearCase_Storage\views\snapshot\ASTest_Project_I +ntegration_Snapshot -gpath d:\ClearCase_Storage\views\snapshot\ASTest +_Project_Integration_Snapshot \\idetestcc1\ccstg_d\views\snapshot\AST +est_Project_Integration_Snapshot d: cd clearcase_storage\views\snapshot\1000_test_snapshot_Int_Snapshot cleartool update -add_loadrules .\InnovComp2\PRJ_1000_test_snapshot
This last section must be done for each input record, so the detail will be different.

Replies are listed 'Best First'.
Re^5: Multiple command prints in same output file
by davidrw (Prior) on Jul 08, 2005 at 14:04 UTC
    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;