in reply to Re^3: 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^5: Log Parsing
by Corion (Patriarch) on Sep 07, 2007 at 12:47 UTC

    Variables interpolate directly in double-quoted strings, so you don't have to do anything extra for the filename. I prefer the three-argument form of open and error checking though:

    use strict; my $count = 0; my $filename = "/home/mj/newlogs$count.log"; open my $filehandle, ">", $filename or die "Couldn't create '$filename': $!"; ... loop print $filehandle $3; ... close $filehandle; $count++;

    The operator for string concatenation is the dot (.) - see perlop for the various operators.

    my $filename = "/home/mj/newlogs$count.log";

    is equivalent to

    my $filename = "/home/mj/newlogs" . $count . ".log";

    Please read print again to see what syntax I used for the print statement. Much of your code was not syntactically valid - for example, Perl wants a semicolon at the end of each statement. Reading perlsyn will help much.

    Also try to get in the habit of using strict and warnings to give Perl a chance to help you when you misspell variable names.