in reply to Logic Question

Looks pretty good to me, at least to visual inspection, except that you try to read from F after you've already read the whole file into @F_cf (so there's nothing left to read). Replace your while loop with a for loop: for my $line (@F_cf) {

Not sure what the final rename is; do you mean to rename your new file to the old name inside the outer for loop.

Replies are listed 'Best First'.
Re^2: Logic Question
by wcj75019 (Acolyte) on Feb 22, 2008 at 23:41 UTC
    Thank you. Very good point. yes, I am going to rename the file. But, see. I can't get the thing to work. I need to break it up into smaller chunks maybe.
      Get it working for one file, with a hardcoded filename. Then see if you are correctly generating a list of files. Then add in the loop over the list of files?
        question: you pointed out earlier. why is my filehandle closing on this. I foreach, get cf, then try to read it. But, it says: ERRROR No such file or directory at ./B.p line 10, <CF> chunk 49. thanks
        1 #!/usr/bin/perl -w 2 use strict; 3 my $agent = "best1agent_start"; 4 my $collect = '/usr/bin/su - patrol /usr/adm/best1_default/bgs +/scripts/best1collect -q>>$LOG 2>>$LOG'; 5 open CF_FILES, "cf.files" or die "Error: $!"; 6 my @cf_files=<CF_FILES>; 7 #close CF_FILES; 8 foreach my $cf(@cf_files){ 9 my $line; 10 open (CF, "$cf") or die "ERRROR $!"; 11 while ($line = <CF>){ 12 if($line =~ /$agent/){ 13 print $line; 14 # $line = "$collect"; 15 # print $line; 16 } 17 } 18 }