pasting done twice

L

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
 
L

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

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
 
L

lerameur

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;}

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);
}

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
 
J

J. Gleixner

lerameur said:
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";
 
D

Dave Weaver

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top