Gossamer Forum
Home : General : Perl Programming :

saving data to text file

Quote Reply
saving data to text file
My script does not work no data is passed to my file
I run this from command line > myfile.txt yes I am a newbie to perl.

#!/bin/perl
# @(#)pscan_accts.pl 1.5
# use DBI qw(:sql_types);
require "/usr/local/lib/DBDFudgeIngres.pl";
# Set up the Ingres environment
$ENV{'II_SYSTEM'} = '/ingresii';
# Use the "mbh" database
$dbname = "mbh";
$sql =<<EOT;
select primary_doctor, surname, given_name_1, given_name_2, marital_st,
ur_number, sex, birth_date, address_1, address_2, address_3, home_phone, ethnicity
from mbhwhipdemographic
where ur_number <> 0
EOT
$rc = IngresExecute($dbname, $sql);
print "\"primary_doctor\", \"surname\", \"given_name_1\", \"given_name_2\", \"marital_st\", ur_number, \"sex\", \"birth_date\", \"address_1\", \"address_2\", \"address_3\", \"home_phone\", \"ethnicity\"\n";
while (IngresFetch()) {
$primary_doctor = $results[0];
$primary_doctor =~ s/"/'/g;
$surname = $results[1];
$surname =~ s/"/'/g;
$given_name_1 = $results[2];
$given_name_1 =~ s/"/'/g;
$given_name_2 = $results[3];
$given_name_2 =~ s/"/'/g;
$marital_st = $results[4];
$marital_st =~ s/"/'/g;
$URnumber = $results[5];
$sex = $results[6];
$birthdate = $results[7];
$birthdate =~ s/\s+//g;
$address_1 = $results[8];
$address_1 =~ s/"/'/g;
$address_2 = $results[9];
$address_2 =~ s/"/'/g;
$address_3 = $results[10];
$address_3 =~ s/"/'/g;
$home_phone = $results[11];
$ethnicity = $results[12];
$ethnicity =~ s/"/'/g;

print "\"$primary_doctor\", \"$surname\", \"$given_name_1\", \"$given_name_2\", \"$marital_st\",\"$Urnumber\", \"$sex\", \"$birth_date\", \"$address_1\", \"$address_2\", \"$address_3\", \"$home_phone\", \"$ethnicity\"\n";
}