---------- Forwarded message ----------
From: J M <jmd...@gmail.com>
Date: Sun, Nov 7, 2010 at 8:27 PM
Subject: Re: error opening file with open function
To: shawn wilson <ag4ve...@gmail.com>


shawn,

I pretty sure it's not a permissions thing but here you go:

[code]
(jmd...@darkstar)-(0)-(07:23 PM Sun Nov 07)->
(~/global_stats)-(5 files, 2.4Mb)--> ls -lh
total 2.3M
-rw-r--r-- 1 jmd9qs sys  203 2010-11-07 12:10 globals.php
-rwxr-xr-x 1 jmd9qs sys 1.6K 2010-11-07 18:50 globals.pl*
-rwxr-xr-x 1 jmd9qs sys 1.6K 2010-11-07 18:48 globals.pl~*
-rw-r--r-- 1 jmd9qs sys  864 2010-11-07 12:39 import.php
-rwxrwxrwx 1 jmd9qs sys 2.3M 2010-11-07 14:15 ish-history.csv*

(jmd...@darkstar)-(0)-(07:23 PM Sun Nov 07)->
(~/global_stats)-(5 files, 2.4Mb)--> whoami
jmd9qs
[\code]


And here's the error I get


[code]
(jmd...@darkstar)-(0)-(07:23 PM Sun Nov 07)->
(~/global_stats)-(5 files, 2.4Mb)--> ./globals.pl
Connected to the database!What is the name of the file (probably
        /home/jmd9qs/global_stats/ish_history.csv)? :
/home/jmd9qs/global_stats/ish_history.csv
Can't open the file "/home/jmd9qs/global_stats/ish_history.csv": No such
file or directory at ./globals.pl line 28, <STDIN> line 1.

(jmd...@darkstar)-(0)-(07:25 PM Sun Nov 07)->
(~/global_stats)-(5 files, 2.4Mb)-->
[\code]


On Sun, Nov 7, 2010 at 8:23 PM, shawn wilson <ag4ve...@gmail.com> wrote:

> 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?
> >>>
> >>
> >>
>

Reply via email to