On 11/9/06, mlist <[EMAIL PROTECTED]> wrote:

First, thanks for your input Jay, Rob, Lawrence

Jay,

I tried your script.  What happens is it gets through the first
iteration of the script and copies the appropriate lines to the new log
file.  But each subsequent iteration is skipped over.

This is what I have:


use warnings;
use strict;
open CULIST, "/root/syslog_stuff/CULIST3.txt" or die $!;

open SEPTEMBER, "/var/log/log_netscreen_sep" or die $!;

while (<CULIST>) {
chomp (my $culist = $_);
print "$culist\n";
open CU_OUTPUT,">> /root/syslog_stuff/monthly_logs/sep2/$culist"or die
$!;

        while (<SEPTEMBER>) {
               chomp;
                print CU_OUTPUT "$_\n\n" if /$culist/;
        #       print "$_\n\n";
        }

}

The script goes through each $culist (shown by printing the each
variable) - but it looks like it's skipping over the "while
(<SEPTEMBER>)" part for the rest of the $culist.  Any ideas?

Matt


Matt,

The problem is that <SEPTEMBER> has already returned EOF. The next
time around, Perl says "nothing more to see here, folks; move along"
and exits the while block. If you want to read from it again, you need
to reopen it. Just put the open inside the while (<CULIST>) block.

Alternatively, you could read the entire file into memory and iterate
over it as an array, take Rob's approach and iterate over a list of
the items from culist.txt for each line of <SEPTMEBER> instead of the
other way around, or take a look at Tie::File.

HTH,

--jay
--------------------------------------------------
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.downloadsquad.com  http://www.engatiki.org

values of β will give rise to dom!

Reply via email to