user2282534
user2282534

Reputation: 39

Parse log file and then redirect outputs to some other file

I am trying in my script to parse some number of files and redirecting the output to some other file. Please help me out, what I am doing wrong. Because I am creating separate file for each output, but it's creating a common .txt file, and my code is not working.

Below is the code for creating output file:

open( $m1logFIle, "> $m1log.txt" ) || die "\n Could not create write file.\n\n";
open( $g1logFIle, "> $g1log.txt" ) || die "\n Could not create write file.\n\n";
open( $V1logFIle, "> $VOD1og.txt") || die "\n Could not create write file.\n\n";

I am printing it to the file with the following code:

print $V1logFIle  "-V1 Success @ $curr_exectime(ms)\n\n";

Upvotes: 0

Views: 84

Answers (2)

TLP
TLP

Reputation: 67910

I am going to make some assumptions here.

  1. You are not using use strict and use warnings, which is why you cannot figure out why this is happening.
  2. When you say but its creating a common file .txt file, you actually mean that it is creating a file with the name .txt.
  3. Your variables $m1log, $g1log and $VOD1og are somehow undefined.

So, to fix this, add

use strict;
use warnings;

to your script and fix the errors and warnings that appear. If your problem still persists, make sure your variables actually contain what you think they do, for example by printing them with the Data::Dumper module:

use Data::Dumper;
...
print Dumper $VOD1og;

You will find that Data::Dumper is an excellent debugging tool.

TL;DR:

my $VOD1og;         # undefined variable
print "> $VOD1og";  # prints "> " because $VOD1og is empty

Without use warnings, no warning is given.

Upvotes: 1

Vijay
Vijay

Reputation: 67221

if there is a variable $m1log existing then it should be

open( $m1logFIle, ">", $m1log.".txt" ) || die "\n Could not create write file.\n\n";

Upvotes: 0

Related Questions