in reply to Multiple command prints in same output file

can you post more (and working -- that open statement is incomplete and missing a ';') code? Especially how you're reading the input file and taking that data (presumably setting the $CreateViewCmd, $ChangeDirectory, and $LoadViewCmd variables) and your loop structures.

Replies are listed 'Best First'.
Re^2: Multiple command prints in same output file
by johangr (Initiate) on Jul 08, 2005 at 12:44 UTC
    Here is the complete piece of code:

    #!/usr/bin/perl -w $DescribeFile = $ARGV[0]; $ComponentFile = $ARGV[1]; $LoadCreateFile = ">".$ARGV[2]; # *** Process the data from the input file *** $Pause .= "pause\n"; &Main_Process; # *** Subroutine that does the main processing of program. *** sub Main_Process { $IntFound = 0; $RootFound = 0; &OpenProjectFile; foreach $_ (@DescribeData) { &ProcessGetViewInfo; } close LOADCREATE; } # *** Subroutine that Opens, reads and closes the input file * +** sub OpenProjectFile { open DESCRIBE, $DescribeFile or die "Can not find the project descri +be file!"; while (!eof(DESCRIBE)) { read DESCRIBE, $DescribeDataFromFile, 100; $DescribeData .= $DescribeDataFromFile; } close DESCRIBE; $DescribeData =~ s/\n\n/\n/g; @DescribeData = split("\n", $DescribeData); } # *** Subroutine that gets the required view info from the file + *** sub ProcessGetViewInfo { &FindTag; } # *** Subroutine that finds and stores the view tag name for the curen +t view *** sub FindTag { if (m/project "/) { $ProjectLine = $_; $PrjLeftQuote = index($ProjectLine, "t"); $NameLength = length($ProjectLine) - $PrjLeftQuote - 4; $ProjectName = substr($ProjectLine, $PrjLeftQuote + 3, $NameLength +); } if (m/integration stream:/) { $DescribeLine = $_; $LeftQuote = index($DescribeLine, ":"); $RightQuote = index($DescribeLine, "@"); $Intname = $RightQuote - $LeftQuote - 2; $Int = substr($DescribeLine, $LeftQuote + 2 , $Intname); $Int2 = substr($DescribeLine, $LeftQuote + 2 , length($DescribeLin +e)); $CreateViewCmd .= "cleartool mkview -snapshot -tag ".$Int."_Snapsh +ot -stream ".$Int2." -colocated_server -host idetestcc1 -hpath d:\\Cl +earCase_Storage\\views\\snapshot\\".$Int."_Snapshot -gpath d:\\ClearC +ase_Storage\\views\\snapshot\\".$Int."_Snapshot \\\\idetestcc1\\ccstg +_d\\views\\snapshot\\".$Int."_Snapshot\n"; $IntFound ++; &OpenComponentFile; foreach $_ (@ComponentData) { &ProcessComponent; } } } # *** Subroutine that Opens, reads and closes the input file * +** sub OpenComponentFile { open COMPONENT, $ComponentFile or die "Can not find the component fi +le!"; while (!eof(COMPONENT)) { read COMPONENT, $CompDataFromFile, 100; $ComponentData .= $CompDataFromFile; } close COMPONENT; $ComponentData =~ s/\n\n/\n/g; @ComponentData = split("\n", $ComponentData); } # *** Subroutine that gets the required view info from the file + *** sub ProcessComponent { &FindRoot; if ($RootFound == 1) { &CreateLoadFile; } } # *** Subroutine that finds and stores the root name for the current p +roject *** sub FindRoot { if (m/$ProjectName/) { if (m/root directory:/) { $RootLine = $_; $LeftQuoteRoot = index($RootLine, ":"); $RightQuoteRoot = length($RootLine) - $LeftQuoteRoot - 4; $Root = substr($RootLine, $LeftQuoteRoot + 3, $RightQuoteRoot); $LoadViewCmd .= "cleartool update -add_loadrules \.".$Root." \n +"; $D .= "d:\n"; $ChangeDirectory .= "cd clearcase_storage\\views\\snapshot\\".$ +Int."_Snapshot\n"; $RootFound ++; } } } # *** Subroutine that opens and prints the load spec file +*** sub CreateLoadFile { open LOADCREATE, $LoadCreateFile or die "Can not find the LoadCreate +File!"; print LOADCREATE $CreateViewCmd; print LOADCREATE $D; print LOADCREATE $ChangeDirectory; print LOADCREATE $LoadViewCmd; print LOADCREATE $Pause; $RootFound = 0; }

    Hope this helps!

      first comment is use strict (among other things this will complain about the undeclared global variable $RootFound) .. after that, I'm confused as to why $LoadCreateFile is opened for writing and _clobbered_ each time.. that will result in just 1 set of print's ever being in there..

      (i meant to ask earlier) could you post a sample of the output you're currently getting and a sample of the desired output?
        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.