pasting done twice

pasting done twice

am 09.10.2007 21:11:10 von lerameur

hello,

below is part of my working program. No errors but the problem I am
facing is that the line: print $out_file $items[86],",";
seems to be activating twice. The purpose of this program is to take a
log file, ( array) and add data in an empty section of that array. Now
it is doing it, but twice. can someone tell how to correct this?
thanks



sub MainProg {

while (my $filename = glob("$year2$month2$day2$hours2*") ){
$temp_file_seq_n=substr($filename,-5,1); #first step to figure out the
logname to reproduce the original traffic log file
print $temp_file_seq_n, "\n";

if ($temp_file_seq_n ==1){
$logname=$logtime."$temp_file_seq_n"."_TLG";
&Parsing;
}
elsif ($temp_file_seq_n ==3){
$logname=$logtime."$temp_file_seq_n"."_TLG";
&Parsing;
}
elsif ($temp_file_seq_n ==5){
$logname=$logtime."$temp_file_seq_n"."_TLG";
&Parsing;
}
else{}

sub Parsing{
my $Oper_directory = '/aaa/Working/output';
chdir($Oper_directory) || die "Fail to change directory: $!\n";
open my $out_file, '>>', $logname."TEST" or die "Can't open
$logname: $!";
print "logname: $logname \n";
my $Oper_D = '/aaa/Working';
chdir($Oper_D) || die "Fail to change directory: $!\n";

open($wordlisting1, '<', $logname) or die "Could not open wordlisting:
$!";
while (my $line = <$wordlisting1> ) {
if ($line =~ m/Beth:8/ ) {
my @items = (split(/,/,$line))[0..85];
$items[86]="696c6c65";
my @items_extra = (split(/,/,$line))[87..88]; #86 is user data
print $out_file join(',', @items),",";
print $out_file $items[86],",";
print $out_file join(',', @items_extra);
}


k

Re: pasting done twice

am 09.10.2007 21:29:09 von lerameur

On Oct 9, 3:11 pm, lerameur wrote:
> hello,
>
> below is part of my working program. No errors but the problem I am
> facing is that the line: print $out_file $items[86],",";
> seems to be activating twice. The purpose of this program is to take a
> log file, ( array) and add data in an empty section of that array. Now
> it is doing it, but twice. can someone tell how to correct this?
> thanks
>
> sub MainProg {
>
> while (my $filename = glob("$year2$month2$day2$hours2*") ){
> $temp_file_seq_n=substr($filename,-5,1); #first step to figure out the
> logname to reproduce the original traffic log file
> print $temp_file_seq_n, "\n";
>
> if ($temp_file_seq_n ==1){
> $logname=$logtime."$temp_file_seq_n"."_TLG";
> &Parsing;}
>
> elsif ($temp_file_seq_n ==3){
> $logname=$logtime."$temp_file_seq_n"."_TLG";
> &Parsing;}
>
> elsif ($temp_file_seq_n ==5){
> $logname=$logtime."$temp_file_seq_n"."_TLG";
> &Parsing;}
>
> else{}
>
> sub Parsing{
> my $Oper_directory = '/aaa/Working/output';
> chdir($Oper_directory) || die "Fail to change directory: $!\n";
> open my $out_file, '>>', $logname."TEST" or die "Can't open
> $logname: $!";
> print "logname: $logname \n";
> my $Oper_D = '/aaa/Working';
> chdir($Oper_D) || die "Fail to change directory: $!\n";
>
> open($wordlisting1, '<', $logname) or die "Could not open wordlisting:
> $!";
> while (my $line = <$wordlisting1> ) {
> if ($line =~ m/Beth:8/ ) {
> my @items = (split(/,/,$line))[0..85];
> $items[86]="696c6c65";
> my @items_extra = (split(/,/,$line))[87..88]; #86 is user data
> print $out_file join(',', @items),",";
> print $out_file $items[86],",";
> print $out_file join(',', @items_extra);
> }
>
> k

by the way, I put a simple print "Traffic \n"; after line: print
$out_file join(',', @items_extra);
and it print only once when the program is executed. So one loop, but
twice the data. At first I thought it was going through the loop
twice, but that is not the case.

k

Re: pasting done twice

am 09.10.2007 21:31:17 von lerameur

On Oct 9, 3:29 pm, lerameur wrote:
> On Oct 9, 3:11 pm, lerameur wrote:
>
>
>
> > hello,
>
> > below is part of my working program. No errors but the problem I am
> > facing is that the line: print $out_file $items[86],",";
> > seems to be activating twice. The purpose of this program is to take a
> > log file, ( array) and add data in an empty section of that array. Now
> > it is doing it, but twice. can someone tell how to correct this?
> > thanks
>
> > sub MainProg {
>
> > while (my $filename = glob("$year2$month2$day2$hours2*") ){
> > $temp_file_seq_n=substr($filename,-5,1); #first step to figure out the
> > logname to reproduce the original traffic log file
> > print $temp_file_seq_n, "\n";
>
> > if ($temp_file_seq_n ==1){
> > $logname=$logtime."$temp_file_seq_n"."_TLG";
> > &Parsing;}
>
> > elsif ($temp_file_seq_n ==3){
> > $logname=$logtime."$temp_file_seq_n"."_TLG";
> > &Parsing;}
>
> > elsif ($temp_file_seq_n ==5){
> > $logname=$logtime."$temp_file_seq_n"."_TLG";
> > &Parsing;}
>
> > else{}
>
> > sub Parsing{
> > my $Oper_directory = '/aaa/Working/output';
> > chdir($Oper_directory) || die "Fail to change directory: $!\n";
> > open my $out_file, '>>', $logname."TEST" or die "Can't open
> > $logname: $!";
> > print "logname: $logname \n";
> > my $Oper_D = '/aaa/Working';
> > chdir($Oper_D) || die "Fail to change directory: $!\n";
>
> > open($wordlisting1, '<', $logname) or die "Could not open wordlisting:
> > $!";
> > while (my $line = <$wordlisting1> ) {
> > if ($line =~ m/Beth:8/ ) {
> > my @items = (split(/,/,$line))[0..85];
> > $items[86]="696c6c65";
> > my @items_extra = (split(/,/,$line))[87..88]; #86 is user data
> > print $out_file join(',', @items),",";
> > print $out_file $items[86],",";
> > print $out_file join(',', @items_extra);
> > }
>
> > k
>
> by the way, I put a simple print "Traffic \n"; after line: print
> $out_file join(',', @items_extra);
> and it print only once when the program is executed. So one loop, but
> twice the data. At first I thought it was going through the loop
> twice, but that is not the case.
>
> k

I removed the line print $out_file $items[86],","; .....

k

Re: pasting done twice

am 09.10.2007 21:53:19 von glex_no-spam

lerameur wrote:
> hello,
>
> below is part of my working program. No errors but the problem I am
> facing is that the line: print $out_file $items[86],",";

> while (my $filename = glob("$year2$month2$day2$hours2*") ){

Wow.. how many times are we going to see this code? Especially without:

use strict;
use warnings;

???

> open($wordlisting1, '<', $logname) or die "Could not open wordlisting:
> $!";

open(my $wordlisting1, '<', $logname)
or die "Could not open $logname: $!";

> while (my $line = <$wordlisting1> ) {
> if ($line =~ m/Beth:8/ ) {

chomp( $line );

> my @items = (split(/,/,$line))[0..85];
> $items[86]="696c6c65";
> my @items_extra = (split(/,/,$line))[87..88]; #86 is user data
> print $out_file join(',', @items),",";
> print $out_file $items[86],",";
> print $out_file join(',', @items_extra);

No need for @items_extra, just overwrite [86] and print the whole thing.

my @items = (split(/,/,$line))[0..88];
$items[86]='696c6c65';
print $out_file join(',', @items ), "\n";

Re: pasting done twice

am 10.10.2007 09:33:46 von Dave Weaver

On Tue, 09 Oct 2007 12:11:10 -0700, lerameur wrote:
>
> my @items = (split(/,/,$line))[0..85];
> $items[86]="696c6c65";
> my @items_extra = (split(/,/,$line))[87..88]; #86 is user data
> print $out_file join(',', @items),",";

Here you print @items, which *includes* $items[86]

> print $out_file $items[86],",";

Here you print $items[86] for the second time.