pasting done twice

Discussion in 'Perl Misc' started by lerameur, Oct 9, 2007.

  1. lerameur

    lerameur Guest

    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
    lerameur, Oct 9, 2007
    #1
    1. Advertising

  2. lerameur

    lerameur Guest

    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
    lerameur, Oct 9, 2007
    #2
    1. Advertising

  3. lerameur

    lerameur Guest

    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
    lerameur, Oct 9, 2007
    #3
  4. lerameur

    J. Gleixner Guest

    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";
    J. Gleixner, Oct 9, 2007
    #4
  5. lerameur

    Dave Weaver Guest

    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.
    Dave Weaver, Oct 10, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Z2FuZXNoX2luZm9zeXM=?=

    pasting xml data into an excel template

    =?Utf-8?B?Z2FuZXNoX2luZm9zeXM=?=, Aug 24, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    674
  2. Captain Chaos

    Request is done twice randomly

    Captain Chaos, Dec 29, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    327
    Captain Chaos
    Dec 30, 2003
  3. Vlado
    Replies:
    0
    Views:
    420
    Vlado
    Nov 21, 2003
  4. Kiuhnm

    twice(twice(x))

    Kiuhnm, Apr 1, 2006, in forum: C++
    Replies:
    2
    Views:
    393
    Kiuhnm
    Apr 1, 2006
  5. Zhidian Du
    Replies:
    0
    Views:
    148
    Zhidian Du
    Feb 21, 2004
Loading...

Share This Page