Reputation: 39
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
Reputation: 67910
I am going to make some assumptions here.
use strict
and use warnings
, which is why you cannot figure out why this is happening.but its creating a common file .txt file
, you actually mean that it is creating a file with the name .txt
.$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
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