Phoenix.pm: PERL-SQL question

Shay Harding kellewic at yahoo.com
Tue Jan 29 21:14:31 CST 2002


$input_file="util.txt";
open(NISHANT,$input_file);
while (<NISHANT>) {
   foreach $lines ($_) {
      chomp $_;
      push (@lines,$lines);
   }
}

I am kind of confused about the above code. Is anything even placed into
@lines? Couldn't this just be written as:

$input_file="util.txt";
open(NISHANT,$input_file);
@lines = <NISHANT>;
close NISHANT;

or better yet since the close() is placed at the end of the code do:

----------------------------------------------------------------------------
-------------
#!/usr/bin/perl
use OLE;
$conn = CreateObject OLE "ADODB.Connection" || die "CreateObject: $!";
$conn->Open('sort_data');   # connect to data source

open NISHANT, "util.txt";
while (<NISHANT>) {
    chomp;
   ($tester, $ww, $util) = split ',';
   $conn->Execute("INSERT into utilization (id, tester_name, ww, util)
VALUES ('$tester', '$ww', '$util ')")
            | | die "Could not execute sql statement: $!";
}

close NISHANT;
$conn->Close();
----------------------------------------------------------------------------
-------------


Shay


----- Original Message -----
From: "N" <nishfish at yahoo.com>
To: <phoenix-pm-list at happyfunball.pm.org>
Sent: Tuesday, January 29, 2002 7:29 PM
Subject: Phoenix.pm: PERL-SQL question


> Hi
> I have a SQL loading question.  have a flat text file
> that is generated every day, the contents of which I
> need loaded into a SQL database. The file is comma
> delimited and each value in the text file corresponds
> to a field in my SQL database. When i extract the
> elements and run the loader against the file, I get
> the following error:
> Could not execute sql statement: at
> C:\Perl\perfloader.pl line 31, <NISHANT> line 6
>   The number at the end ie: 6 corresponds to the
> number of entries in the flat text file.
> I have attached my loader program and the text file as
> well and was wondering if any body knew what the issue
> was.
> Also, I have a text file, the values that are
> delimited by "|" and  Iam having difficulty using the
> split command to extract the elements.
> Thank you
> Rgds
> Nishant
> PS: I use a system DSN connection against the SQL db
>
>
> __________________________________________________
> Do You Yahoo!?
> Great stuff seeking new owners in Yahoo! Auctions!
> http://auctions.yahoo.com


----------------------------------------------------------------------------
----


> TER01,04,98.60%
> TER02,04,98.90%
> TER03,05,76.98%
> TER04,05,76.98%
> TER05,05,76.98%
> TER06,05,76.98%


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com




More information about the Phoenix-pm mailing list