Do an 'ls -l' and a 'whoami' and post the result. Also post the error your
program gives.
On Nov 7, 2010 9:19 PM, "J M" <jmd...@gmail.com> wrote:
> I did hardcode the name in the first version of the script... in two
forms:
> 'file.txt' and '/home/path/to/myfile/file.txt'. Neither made any
difference.
>
> Thank you for assisting!
>
> On Sun, Nov 7, 2010 at 8:12 PM, Parag Kalra <paragka...@gmail.com> wrote:
>
>> Instead of taking the file as an input parameter, try to parse the file
by
>> hard coding its name in the script and let us know the outcome.
>>
>> Cheers,
>> Parag
>>
>>
>>
>>
>> On Sun, Nov 7, 2010 at 6:00 PM, J M <jmd...@gmail.com> wrote:
>>
>>> Hi all,
>>>
>>> I'm having great issues with my program at the moment... it is supposed
to
>>> take a csv file and parse it, with the output being stored in a MySQL
>>> database. The problem I'm having is that the file I need to parse
>>> ('ish_history.csv') will not open in the program for some reason. I know
>>> the
>>> file exists, I'm on a linux system and the file is world-readable, and
>>> I've
>>> tried placing the file in the directory the script is run from AS WELL
as
>>> using full path names to said file... all has resulted in no luck, and
I'm
>>> getting the "No such file or directory" error. Here is my code so far:
>>>
>>>
>>>
>>> [code]
>>> #! /usr/bin/perl
>>> #
>>> use DBI;
>>> use DBD::mysql;
>>> use Text::CSV;
>>>
>>>
>>> #configure variables
>>> my $host = "localhost";
>>> my $db = "somefakedatabase";
>>> my $table = "somefaketable";
>>> my $user = "somefakeuser";
>>> my $password = "yeahrightlikethisismyrealpasswordLOL";
>>>
>>> #connect to the database
>>> my $dbc = "dbi:mysql:$db:$host";
>>> if(my $dbh = DBI->connect($dbc, $user, $password) or die "Can't connect
to
>>> the
>>> database: $DBI::errstr\n") {
>>> print "Connected to the database!";
>>> }
>>>
>>> #setup parser
>>> my $csv = Text::CSV->new();
>>> print "What is the name of the file? : ";
>>> chomp(my $file = <STDIN>);
>>>
>>> open CSV, "<", $file or die "Can't open the file \"$file\":
>>> $!";
>>> while(<CSV>) {
>>> next if ($. == 1);
>>> if ($csv->parse($_)) {
>>> my @columns = $csv->fields();
>>> my $myquery = $dbh->prepare('insert into $table
>>>
>>>
(station_number,WBAN_number,station_name,country,fips,state,ICAO_callsign,lattitude,longitude,elevation)
>>> values ($columns[0], $columns[1], **truncated**
>>> $myquery->execute();
>>> $dbh->disconnect();
>>> } else {
>>> my $err = $csv->error_input;
>>> print "Failed to parse line: $err";
>>> }
>>> }
>>> close CSV;
>>> closedir TMPDIR;
>>> [\code]
>>>
>>> Any ideas as to why this isn't working?
>>>
>>
>>