Hi there
I read carefully everybodys opinions and found the .. operator
to be the simplest way to do it. Altough, I think I didn't express myself very well since your code (in general) is very complex on the regex side altough its valid it is not necessary for the simple thing I needed to to wich I paste bellow.
I abandoned the @array solutions because Im linking 1,2 - 1,3 giga files :)
Nevertheless I deeply thank you all for your fast replies and for sharing with me that bit of knowledge.
ps: I actually found fun in those while in while solutions :) geeee what a geek!
How it will stay
#!/usr/bin/perl
use warnings;
use strict;
#It needs ARGS and readable file
my $logfile=$ARGV[0];
my $contract=$ARGV[1];
unless (@ARGV == 2) {
print "USAGE: $0 \"logfile\" \"numero\"\n";
exit(1);
}
my $output="/tmp/session_".$contract.".txt";
unless (-e $logfile) {
print "O ficheiro $logfile usado para input n\343o existe. Verifique
+o nome do mesmo sff.\n";
exit(1);
}
if (-e $output) {
unlink($output);
}
open(OUTPUT,">>",$output) or die("Could not open conf file.");
open(LOG, $logfile) or die("Could not open conf file.");
while (<LOG>) {
if (/:NOTICE:user=$contract,session=\d+:/ .. /\)\[/) {
print OUTPUT $_
}
}
close(LOG);
close(OUTPUT);
Actually I allready had acomplish that result using a marker with a var and is actually 7 seconds faster than the .. operator, but, I have deprecate it because is better coded with the above script (IMHO).
open(OUTPUT,">>",$output) or die("Could not open conf file.");
open(LOG, $logfile) or die("Could not open conf file.");
while (defined($line = <LOG>) ) {
if ($line =~/:NOTICE:user=$contract,session=(\d+):/) {
print OUTPUT $line;
$echo=1;
} elsif ($echo == 1) {
print OUTPUT $line;
if ($line =~/\)\[/) {
$echo=0;
}
}
}
|