[23027] in Perl-Users-Digest
Perl-Users Digest, Issue: 5247 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 21 00:10:43 2003
Date: Sun, 20 Jul 2003 21:10:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 20 Jul 2003 Volume: 10 Number: 5247
Today's topics:
Retrieving Data from Microsoft Access Database using Pe <thomas.rawley@duke.edu>
Re: Retrieving Data from Microsoft Access Database usin <bwalton@rochester.rr.com>
Re: Retrieving Data from Microsoft Access Database usin <thomas.rawley@duke.edu>
Re: Retrieving Data from Microsoft Access Database usin <bwalton@rochester.rr.com>
Re: sinfo script, xchat, slackware <ben.goldberg@hotpop.com>
Re: sinfo script, xchat, slackware <asu1@c-o-r-n-e-l-l.edu>
Re: Variable definition help needed <bwalton@rochester.rr.com>
Re: Write a loop <ben.goldberg@hotpop.com>
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 20 Jul 2003 21:02:38 -0400
From: "Thomas Rawley" <thomas.rawley@duke.edu>
Subject: Retrieving Data from Microsoft Access Database using Perl
Message-Id: <bffe3h$7ed$1@gargoyle.oit.duke.edu>
I am on a Windows machine and I need to acess some data in a MS Access
database so I can display it on a website. Both the perl script and the
database file are currently in the same directory on the same computer
(Windows XP). I have ActivePerl installed and downloaded and installed both
the DBI and DBD::ODBC modules using ppm.
When I try to run the script, I get and error saying the data source name
was not found and no default driver specified. The code is below. Any help
on this would be wonderful. Thanks in advance.
use DBI;
$DSN = 'driver=Mircosoft Access Driver (*.mdb);dbq=MyEasinetEvents.mdb';
$dbh = DBI->connect("dbi:ODBC:$DSN",'','');
$sth = $dbh->prepare("SELECT * FROM Events");
$sth->execute();
print "Content-type:text/html\n\n";
print "<html><body><h1>Fingerprint Scanner Records</h1>";
print "<table>\n";
print
"<tr><th>EventID</th><th>EventTime</th><th>EventType</th><th>Address</th><th
>SubAddr</th><th>UserID</th><th>CardNo</th><th>Details</th><th>LinkedEvent</
th><th>Archived</th></tr>\n";
while( @row = $sth->fetchrow_array )
{
print "<tr>";
foreach $field (@row)
{
print "<td>$field</td>";
}
print "</tr>";
}
print "</table>\n";
print "</body></html>";
$sth->finish;
$dbh->disconnect;
Thomas
------------------------------
Date: Mon, 21 Jul 2003 02:15:45 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Retrieving Data from Microsoft Access Database using Perl
Message-Id: <3F1B4CC9.8020708@rochester.rr.com>
Thomas Rawley wrote:
> I am on a Windows machine and I need to acess some data in a MS Access
> database so I can display it on a website. Both the perl script and the
> database file are currently in the same directory on the same computer
> (Windows XP). I have ActivePerl installed and downloaded and installed both
> the DBI and DBD::ODBC modules using ppm.
>
> When I try to run the script, I get and error saying the data source name
> was not found and no default driver specified. The code is below. Any help
> on this would be wonderful. Thanks in advance.
>
> use DBI;
>
> $DSN = 'driver=Mircosoft Access Driver (*.mdb);dbq=MyEasinetEvents.mdb';
-------------------^^
Also, you might need the full path to your .mdb file, even if it is in
the same directory as your program -- especially since you seem to be
running this as a CGI script. Probably a better way is to define a
system DSN using the ODBC tool in the Control Panel (don't use a user
DSN if you want to hook it to your web server). You just use the name
you assigned to that entry as your DSN in your connect statement. If
you called it "foo", $DSN='foo'; would do the trick. That prevents the
sort of snafu indicated above, and removes the worry about where the
database file is located, typos in the path, etc.
> $dbh = DBI->connect("dbi:ODBC:$DSN",'','');
Always test to see if things are successful. If you don't, you'll never
know where they went wrong. This goes for just about every call to DBI
methods, unless you use the RaiseError flag in your connect statement.
Something like:
die "horribly because of $DBI::errstr" unless $dbh;
>
> $sth = $dbh->prepare("SELECT * FROM Events");
>
> $sth->execute();
>
> print "Content-type:text/html\n\n";
If you are doing CGI, then for heavens sake:
use CGI;
and take full advantage of it.
> print "<html><body><h1>Fingerprint Scanner Records</h1>";
> print "<table>\n";
>
> print
> "<tr><th>EventID</th><th>EventTime</th><th>EventType</th><th>Address</th><th
>
>>SubAddr</th><th>UserID</th><th>CardNo</th><th>Details</th><th>LinkedEvent</
>>
> th><th>Archived</th></tr>\n";
>
> while( @row = $sth->fetchrow_array )
> {
> print "<tr>";
>
> foreach $field (@row)
> {
> print "<td>$field</td>";
> }
>
> print "</tr>";
> }
>
> print "</table>\n";
> print "</body></html>";
>
> $sth->finish;
> $dbh->disconnect;
>
> Thomas
General comment: By the time you have connected to your Access database
in a CGI script, you'll wish you'd used something else (that is, the
connection process uses a lot of time). A dbm-type hash-key "database"
would be far faster.
--
Bob Walton
------------------------------
Date: Sun, 20 Jul 2003 23:26:20 -0400
From: "Thomas Rawley" <thomas.rawley@duke.edu>
Subject: Re: Retrieving Data from Microsoft Access Database using Perl
Message-Id: <bffmhg$acg$1@gargoyle.oit.duke.edu>
Thanks for your quick response. I am very new to Perl and the code comes
from a book I have. I tried the ODBC in the Control Panel and it seemed to
work fine. Now I just have to figure out how to get this up and running on
the internet (it runs fine on the local machine). I appreciate your help.
Thomas
"Bob Walton" <bwalton@rochester.rr.com> wrote in message
news:3F1B4CC9.8020708@rochester.rr.com...
> Thomas Rawley wrote:
>
> > I am on a Windows machine and I need to acess some data in a MS Access
> > database so I can display it on a website. Both the perl script and the
> > database file are currently in the same directory on the same computer
> > (Windows XP). I have ActivePerl installed and downloaded and installed
both
> > the DBI and DBD::ODBC modules using ppm.
> >
> > When I try to run the script, I get and error saying the data source
name
> > was not found and no default driver specified. The code is below. Any
help
> > on this would be wonderful. Thanks in advance.
> >
> > use DBI;
> >
> > $DSN = 'driver=Mircosoft Access Driver (*.mdb);dbq=MyEasinetEvents.mdb';
>
> -------------------^^
>
> Also, you might need the full path to your .mdb file, even if it is in
> the same directory as your program -- especially since you seem to be
> running this as a CGI script. Probably a better way is to define a
> system DSN using the ODBC tool in the Control Panel (don't use a user
> DSN if you want to hook it to your web server). You just use the name
> you assigned to that entry as your DSN in your connect statement. If
> you called it "foo", $DSN='foo'; would do the trick. That prevents the
> sort of snafu indicated above, and removes the worry about where the
> database file is located, typos in the path, etc.
>
>
> > $dbh = DBI->connect("dbi:ODBC:$DSN",'','');
>
>
> Always test to see if things are successful. If you don't, you'll never
> know where they went wrong. This goes for just about every call to DBI
> methods, unless you use the RaiseError flag in your connect statement.
> Something like:
>
> die "horribly because of $DBI::errstr" unless $dbh;
>
>
> >
> > $sth = $dbh->prepare("SELECT * FROM Events");
> >
> > $sth->execute();
> >
> > print "Content-type:text/html\n\n";
>
>
> If you are doing CGI, then for heavens sake:
>
> use CGI;
>
> and take full advantage of it.
>
>
> > print "<html><body><h1>Fingerprint Scanner Records</h1>";
> > print "<table>\n";
> >
> > print
> >
"<tr><th>EventID</th><th>EventTime</th><th>EventType</th><th>Address</th><th
> >
>
>>SubAddr</th><th>UserID</th><th>CardNo</th><th>Details</th><th>LinkedEvent<
/
> >>
> > th><th>Archived</th></tr>\n";
> >
> > while( @row = $sth->fetchrow_array )
> > {
> > print "<tr>";
> >
> > foreach $field (@row)
> > {
> > print "<td>$field</td>";
> > }
> >
> > print "</tr>";
> > }
> >
> > print "</table>\n";
> > print "</body></html>";
> >
> > $sth->finish;
> > $dbh->disconnect;
> >
> > Thomas
>
>
> General comment: By the time you have connected to your Access database
> in a CGI script, you'll wish you'd used something else (that is, the
> connection process uses a lot of time). A dbm-type hash-key "database"
> would be far faster.
>
> --
> Bob Walton
>
------------------------------
Date: Mon, 21 Jul 2003 03:57:53 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Retrieving Data from Microsoft Access Database using Perl
Message-Id: <3F1B64B9.6020901@rochester.rr.com>
Thomas Rawley wrote:
> Thanks for your quick response. I am very new to Perl and the code comes
> from a book I have. I tried the ODBC in the Control Panel and it seemed to
> work fine. Now I just have to figure out how to get this up and running on
> the internet (it runs fine on the local machine). I appreciate your help.
>
> Thomas
You're welcome. Two things:
First, don't top-post (that's when you put your reply ahead of the text
you are responding to, like you just did).
Second, regarding getting your program to work as a CGI script, I
strongly recommend that you start with a "hello world" type CGI script
and get it working. Then add parameters, test database pieces, and so
forth to it one at a time. When you have that working, then go for your
full-blown application. For a nice reference of stuff to look out for, see:
perldoc -q 500
The references given there are tedious, but that's what CGI is about --
lots of little details, most of which are not intuitively obvious the
first time you see them, and all of which have to be exactly right. And
also note that CGI problems are generally not Perl problems (you would
have the same troubles no matter what language the CGI programs were
written in), hence they are off-topic for this newsgroup. They are
on-topic for comp.infosystems.www.authoring.cgi, but, as usual, make
sure you've exhausted their FAQs before posting.
Note also that the CGI module and in particular:
use CGI::Carp qw(fatalsToBrowser);
is a godsend for CGI work.
... <stuff after top-post deleted>
--
Bob Walton
------------------------------
Date: Sun, 20 Jul 2003 22:24:58 -0400
From: Benjamin Goldberg <ben.goldberg@hotpop.com>
Subject: Re: sinfo script, xchat, slackware
Message-Id: <3F1B4EFA.7DB6FD2A@hotpop.com>
"A. Sinan Unur" wrote:
> NeoSadist wrote:
>
> > A. Sinan Unur wrote:
> >>
> >> Do you get an error "Undefined subroutine &main::cat called at c.pl"
> >> for the line above? I think you need to use the backtick operator
> >> here. Or, you could just open the file and read from it.
> >
> > No, I get no error, just that the output is not correct, as I said in
> > my post.
>
> Well, you are calling cat as if it is a Perl subroutine, not an external
> command whose output you want to read. In any case, you would be better
> off just opening /proc/meminfo and reading from it directly. However, if
> you do insist on using the cat program, you should do:
>
> my @resources = `cat /proc/meminfo`;
[snip]
> > @resources = cat("/proc/meminfo");
How do you know that the OP hasn't done "use Shell qw(cat);" ? :)
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: 21 Jul 2003 02:43:39 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: sinfo script, xchat, slackware
Message-Id: <Xns93BEE73445824asu1cornelledu@132.236.56.8>
Benjamin Goldberg <ben.goldberg@hotpop.com> wrote in
news:3F1B4EFA.7DB6FD2A@hotpop.com:
> "A. Sinan Unur" wrote:
>> NeoSadist wrote:
>>
>> > A. Sinan Unur wrote:
>> >>
>> >> Do you get an error "Undefined subroutine &main::cat
>> >> for the line above? I think you need to use the backtick operator
>> >> here. Or, you could just open the file and read from it.
>> >
>> > No, I get no error, just that the output is not correct, as I said
>> > in my post.
>>
>> Well, you are calling cat as if it is a Perl subroutine, not an
>> external command whose output you want to read. In any case, you
>> would be better off just opening /proc/meminfo and reading from it
>> directly. However, if you do insist on using the cat program, you
>> should do:
>>
>> my @resources = `cat /proc/meminfo`;
> [snip]
>> > @resources = cat("/proc/meminfo");
>
> How do you know that the OP hasn't done "use Shell qw(cat);" ? :)
Well, you are right, I do not. Admittedly, I wasn't even aware of Shell.
BTW, it is for those reasons that I added:
>> Please post a small, self-contained program that shows the erroneous
>> output as well as the output you expect.
elsewhere. All we have to go with is the sub he posted.
Sinan.
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: Mon, 21 Jul 2003 02:32:05 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Variable definition help needed
Message-Id: <3F1B509D.8080009@rochester.rr.com>
Anthony Litton wrote:
> OK, this is in reference to my CgiComments problem, which asked for help on
> on the 16th. The following lines are at the beginning of the script:
>
> my($cgiquery) = new CGI;
> my($blog_id) = $cgiquery->param('blog_id');
>
> 'blog_id' is an eighteen digit number, and for some reason I'm having
> problems creating correctly named files. The final digit is always 0,
> mysteriously. Would it be possible for me to define $blog_id as being only
> the first seventeen, or sixteen digits of 'blog_id'?
...
The chances are pretty good that somewhere along the way, you did
something to $blog_id which converted it to a number and back.
Something like incrementing it, adding a constant to it, or applying any
other operator that forces a numeric context. If you don't do any of
that, it will stay a string, and the last digit would not change. This
scenario is likely because many platforms Perl runs on have about 17
digits of precision in their floating point values -- and Perl may use
such values when it stores scalars in numeric context.
--
Bob Walton
------------------------------
Date: Sun, 20 Jul 2003 21:55:05 -0400
From: Benjamin Goldberg <ben.goldberg@hotpop.com>
Subject: Re: Write a loop
Message-Id: <3F1B47F9.8925539D@hotpop.com>
Ron wrote:
>
> Would you show me how I can write this as a loop?
my $Num_Files = 0;
my $i = 0;
foreach my $s (
$size_file , $size_file2, $size_file3,
$size_file4, $size_file5, $size_file6,
$size_file7, $size_file8, $size_file9 ) {
++$i;
$Num_files = $i if $s;
}
Of course, if you had put your file sizes into an array, instead of 9 different scalars, you could have done:
my ($Num_files) = reverse 0, grep $size_file[$_-1], 1..9;
If your $size_file...$size_file9 variables are package variables,
then you could do the same thing with evil symbolic references.
my ($Num_files) = reverse 0, grep ${"size_file" . ($_ == 1 ? "" : $_)}, 1..9;
But don't do that.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 5247
***************************************