Hello,
I'm trying to write to some text files but it doesn't appear to be writing to the files UNLESS I use the >> operator (append operator) when opening the file. Can anyone tell me what is going on? Below is my code which writes fine when I use the >> operator. If I remove it though nothing gets written to the file.
All help is appreciated!
I'm trying to write to some text files but it doesn't appear to be writing to the files UNLESS I use the >> operator (append operator) when opening the file. Can anyone tell me what is going on? Below is my code which writes fine when I use the >> operator. If I remove it though nothing gets written to the file.
All help is appreciated!
Code:
use strict;
open(SOURCE, $ARGV[0]);
if( -e "labels.txt")
{
if (-w "labels.txt")
{
open(LABELS, ">>labels.txt");
}
else
{
print "File labels.txt is not wrtitable\n";
exit();
}
}
else
{
print "File labels.txt does not exist. Please create this file first and then run this script\n";
exit();
}
if( -e "tables.txt")
{
if (-w "tables.txt")
{
open(TABLES, ">>tables.txt");
}
else
{
print "File tables.txt is not wrtitable\n";
exit();
}
}
else
{
print "File tables.txt does not exist. Please create this file first and then run this script\n";
exit();
}
if( -e "columns.txt")
{
if (-w "columns.txt")
{
open(COLUMNS, ">>columns.txt");
}
else
{
print "File columns.txt is not wrtitable\n";
exit();
}
}
else
{
print "File columns.txt does not exist. Please create this file first and then run this script\n";
exit();
}
while (<SOURCE>)
{
chomp;
$_ =~ s/ //g;
if($_ =~ m/:\s*(.+)\s*\(.+\."(\w+)""(\w+)/)
{
print "Extracting information for $_\n";
print LABELS "$1\n";
print TABLES "$2\n";
print COLUMNS "$3\n";
}
}
#need to close the file in order to 'commit the write operations
close SOURCE;
close LABELS;
close TABLES;
close COLUMNS;