in reply to Re: Log Parsing
in thread Log Parsing

$count = 0; open filehandle, >"/home/mj/newlogs"+$count+".log" print filehandle, $3 close filehandle $count++;
Something like that?? Thanks in advance.

Replies are listed 'Best First'.
Re^3: Log Parsing
by moritz (Cardinal) on Sep 07, 2007 at 12:56 UTC
    No.
    open filehandle, ">", "/home/mj/newlogs$count.log"; # or open filehandle, '>', '/home/mj/newlogs/ . $count . '.log';
    Additionally you should check if open succeeded: open filehandle, ">", "/home/mj/newlogs$count.log" or die "Can't write to file: $!";

    (Update: fixed typo spotted by Corion++)

      @files = glob "*.log"; $count = 1; foreach $file (@files) { next unless $file =~ /planetlab/; open FILE, ">", "/home/mj/ipAddresses$count.log" or die "Can't wri +te to file: $!"; print FILE "begin\n"; local($\, $,) = ("\n", " "); while(<>) { if(/([\d:.]+).*?\bReceived.*?\bBT_PIECE.*?\bdata.*?\bPeer: (\w +):\s+(\d+\.\d+\.\d+\.\d+):\s*(\d+)/) { print FILE $3; } } print FILE "end"; print "$file\n"; close FILE; $count++; }
Re^3: Log Parsing
by FunkyMonk (Bishop) on Sep 07, 2007 at 16:18 UTC
    Just for completeness, this doesn't do what you think it does:
    print filehandle, $3

    To print to a filehandle use print FILEHANDLE VALUES. Notice the lack of a comma between FILEHANDLE and VALUES. The correct version of your print would be:

    print filehandle $3