[16161] in Perl-Users-Digest
Perl-Users Digest, Issue: 3573 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 10 17:13:15 2000
Date: Mon, 10 Jul 2000 14:13:02 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <963263582-v9-i3573@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 10 Jul 2000 Volume: 9 Number: 3573
Today's topics:
HTTP::Daemon problem mnanao@my-deja.com
Re: HTTP::Daemon problem <bwalton@rochester.rr.com>
Re: HTTP::Daemon problem mnanao@sbl.salk.edu
I can't find what's wrong. <shawnball@uswest.net>
Re: I can't find what's wrong. <care227@attglobal.net>
Re: I can't find what's wrong. <nnickee@nnickee.com>
Re: I can't find what's wrong. (brian d foy)
Re: I can't find what's wrong. <ComPete12@yahoo.com>
Re: I can't find what's wrong. <gellyfish@gellyfish.com>
i dont know what to do!! <Treku@w.pl>
ImageMagick with Perl 5.6.0 on Windows NT <prade@espace-formation.com>
Re: ImageMagick with Perl 5.6.0 on Windows NT <ronnie@catlover.com>
Re: ImageMagick with Perl 5.6.0 on Windows NT <hyagillot@tesco.net>
Re: Include a C function (or any *.h) in Perl code (brian d foy)
include my sub in @INC <ydzhang@iastate.edu>
Re: include my sub in @INC (Andrew Johnson)
Re: include my sub in @INC (David Efflandt)
inserting a list of files and their titles <theborg@usa.com>
Re: inserting a list of files and their titles <bwalton@rochester.rr.com>
Re: inserting a list of files and their titles <care227@attglobal.net>
Re: inserting a list of files and their titles <care227@attglobal.net>
Re: inserting a list of files and their titles <iltzu@sci.invalid>
Re: inserting a list of files and their titles <care227@attglobal.net>
Re: inserting a list of files and their titles <iltzu@sci.invalid>
Re: inserting a list of files and their titles <theborg@usa.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 03 Jul 2000 19:37:51 GMT
From: mnanao@my-deja.com
Subject: HTTP::Daemon problem
Message-Id: <8jqq2d$12v$1@nnrp1.deja.com>
Hi All,
I'm having a strange problem with HTTP::Dameon. Specifically,
it dies fatally without any error messages in the send_basic_header
method. I managed to track down the offending line by putting in some
crude debugging (since I'm not very good with the perl debugger)..
here is the method from HTTP::Daemon that I marked up:
sub send_basic_header
{
my $self = shift;
return if $self->antique_client;
$self->send_status_line(@_);
print $self "Date: ", time2str(time), $CRLF;
my $product = $self->daemon->product_tokens;
print $self "Server: $product$CRLF" if $product;
}
and here is my temporary version:
sub send_basic_header
{
my $self = shift;
return if $self->antique_client;
print "SBH_1 ",@_,"\n";
$self->send_status_line(@_); print "SBH_1BB \n";
print "SBH_1B \n";
print "SBH_1BA ","Date: ", time2str(time)
print "SBH_1BB \n";
eval {
print $self "Date: ", time2str(time), $CRLF || print "ERROR $!";
};
print "SBH_2 \n";
my $product = $self->daemon->product_tokens;
print "SBH_3 \n";
print $self "Server: $product$CRLF" if $product;
print "SBH_4 \n";
}
this is what comes out:
SBH_1 200
SBH_1B
SBH_1BA Date: Fri, 30 Jun 2000 18:34:11 GMT
SBH_1BB
then it dies fatally. Does anyone know what this could be?
STDOUT is autoflushed, by the way.
Max
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 04 Jul 2000 00:42:00 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: HTTP::Daemon problem
Message-Id: <39613320.B063110E@rochester.rr.com>
mnanao@my-deja.com wrote:
>
> Hi All,
> I'm having a strange problem with HTTP::Dameon. Specifically,
> it dies fatally without any error messages in the send_basic_header
> method. I managed to track down the offending line by putting in some
> crude debugging (since I'm not very good with the perl debugger)..
> here is the method from HTTP::Daemon that I marked up:
>
> sub send_basic_header
> {
> my $self = shift;
> return if $self->antique_client;
> $self->send_status_line(@_);
> print $self "Date: ", time2str(time), $CRLF;
> my $product = $self->daemon->product_tokens;
> print $self "Server: $product$CRLF" if $product;
> }
>
> and here is my temporary version:
>
> sub send_basic_header
> {
> my $self = shift;
> return if $self->antique_client;
> print "SBH_1 ",@_,"\n";
> $self->send_status_line(@_); print "SBH_1BB \n";
> print "SBH_1B \n";
> print "SBH_1BA ","Date: ", time2str(time)
;----------------------------------------------^
(please copy-paste your code; don't retype it)
> print "SBH_1BB \n";
> eval {
> print $self "Date: ", time2str(time), $CRLF || print "ERROR $!";
> };
> print "SBH_2 \n";
> my $product = $self->daemon->product_tokens;
> print "SBH_3 \n";
> print $self "Server: $product$CRLF" if $product;
> print "SBH_4 \n";
> }
>
> this is what comes out:
>
> SBH_1 200
> SBH_1B
> SBH_1BA Date: Fri, 30 Jun 2000 18:34:11 GMT
> SBH_1BB
>
> then it dies fatally. Does anyone know what this could be?
Maybe someone might have a clue if you hold us exactly how it dies
fatally. Like what, exactly, does it say? And what is your platform,
OS, Perl version, etc?
Just speculating: The || operator has a higher precedence than the ,
operator. Use parens or use or in the statement inside the eval{...}.
BTW, what is the intended reason for using the eval{...} around the
print? If it is to permit continuation in the face of an error, you
should check to see if a syntax error occurred inside the eval ($@).
...
> Max
...
--
Bob Walton
------------------------------
Date: Tue, 04 Jul 2000 17:42:44 GMT
From: mnanao@sbl.salk.edu
Subject: Re: HTTP::Daemon problem
Message-Id: <8jt7mh$n51$1@nnrp1.deja.com>
In article <39613320.B063110E@rochester.rr.com>,
Bob Walton <bwalton@rochester.rr.com> wrote:
> mnanao@my-deja.com wrote:
> >
> > Hi All,
> > I'm having a strange problem with HTTP::Dameon. Specifically,
> > it dies fatally without any error messages in the send_basic_header
> > method. I managed to track down the offending line by putting in some
> > crude debugging (since I'm not very good with the perl debugger)..
> > here is the method from HTTP::Daemon that I marked up:
> >
> > sub send_basic_header
> > {
> > my $self = shift;
> > return if $self->antique_client;
> > $self->send_status_line(@_);
> > print $self "Date: ", time2str(time), $CRLF;
> > my $product = $self->daemon->product_tokens;
> > print $self "Server: $product$CRLF" if $product;
> > }
> >
> > and here is my temporary version:
> >
> > sub send_basic_header
> > {
> > my $self = shift;
> > return if $self->antique_client;
> > print "SBH_1 ",@_,"\n";
> > $self->send_status_line(@_); print "SBH_1BB \n";
> > print "SBH_1B \n";
> > print "SBH_1BA ","Date: ", time2str(time)
> ;----------------------------------------------^
I did copy-paste it... I'm not sure where the semi-colon went!
> (please copy-paste your code; don't retype it)
> > print "SBH_1BB \n";
> > eval {
> > print $self "Date: ", time2str(time), $CRLF || print "ERROR $!";
> > };
> > print "SBH_2 \n";
> > my $product = $self->daemon->product_tokens;
> > print "SBH_3 \n";
> > print $self "Server: $product$CRLF" if $product;
> > print "SBH_4 \n";
> > }
> >
> > this is what comes out:
> >
> > SBH_1 200
> > SBH_1B
> > SBH_1BA Date: Fri, 30 Jun 2000 18:34:11 GMT
> > SBH_1BB
> >
> > then it dies fatally. Does anyone know what this could be?
>
> Maybe someone might have a clue if you hold us exactly how it dies
> fatally. Like what, exactly, does it say? And what is your platform,
> OS, Perl version, etc?
Perl 5.005_03 , SunOS 5.7 Generic_106541-08 sun4u sparc SUNW
HTTP::Daemon:
# $Id: Daemon.pm,v 1.21 1999/03/20 07:37:35 gisle Exp $
see the first 5 lines of mypost, too: there is no error message being produced
by either my marked up HTTP::Daemon *OR* the distribution.
>
> Just speculating: The || operator has a higher precedence than the ,
> operator. Use parens or use or in the statement inside the eval{...}.
> BTW, what is the intended reason for using the eval{...} around the
> print? If it is to permit continuation in the face of an error, you
> should check to see if a syntax error occurred inside the eval ($@).
I've done that. The eval was in fact to trap the error, but it never gets
through the eval block, which is one of the reasons why I am having
trouble tracking this problem down!
> ...
> > Max
> ...
> --
> Bob Walton
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 7 Jul 2000 23:54:10 -0700
From: "Ferk Da Jerk" <shawnball@uswest.net>
Subject: I can't find what's wrong.
Message-Id: <9Zz95.605$lJ1.409424@news.uswest.net>
I have this really easy script, but when I run it I get a 500 error. All
the things are at 777. The script is below. Can any one tell me what's
wrong with it?
#!/usr/bin/perl
open (WRITEFILE, ">../../../cgi-bin/practice/other.htm");
print WRITEFILE "Hello World!";
close (WRITEFILE);
------------------------------
Date: Sat, 08 Jul 2000 01:06:56 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: I can't find what's wrong.
Message-Id: <3966B6F0.A44A4B1F@attglobal.net>
Ferk Da Jerk wrote:
>
> I have this really easy script, but when I run it I get a 500 error. All
> the things are at 777. The script is below. Can any one tell me what's
> wrong with it?
>
> #!/usr/bin/perl
>
> open (WRITEFILE, ">../../../cgi-bin/practice/other.htm");
> print WRITEFILE "Hello World!";
> close (WRITEFILE);
Read the FAQ. Search the Deja archives. Do anything but ask about
that wretched error here. It has been covered a bazillion times.
------------------------------
Date: Sat, 08 Jul 2000 00:20:10 -0500
From: Nnickee <nnickee@nnickee.com>
Subject: Re: I can't find what's wrong.
Message-Id: <5774FE7D961399AC.8A44D50682C1028A.FFD6A7EFD84BE637@lp.airnews.net>
On Fri, 7 Jul 2000 23:54:10 -0700, someone claiming to be "Ferk Da
Jerk" <shawnball@uswest.net> said:
>I have this really easy script, but when I run it I get a 500 error. All
>the things are at 777. The script is below. Can any one tell me what's
>wrong with it?
what happens when you run it from the command line?
>#!/usr/bin/perl
no -w ?
no use strict?
>open (WRITEFILE, ">../../../cgi-bin/practice/other.htm");
not checking to see if the file opened?
>print WRITEFILE "Hello World!";
>close (WRITEFILE);
#!/usr/bin/perl -w
use strict;
print "Check out ";
print "http://www.cpan.org/doc/FAQs/cgi/idiots-guide.html\n";
open (WRITEFILE, ">../../../cgi-bin/practice/other.htm") or die "can't
open ../../../cgi-bin/practice/other.htm: $!";
print WRITEFILE "Hello World!";
close (WRITEFILE);
HTH
Nnickee
------------------------------
Date: Sat, 08 Jul 2000 02:36:18 -0400
From: brian@smithrenaud.com (brian d foy)
Subject: Re: I can't find what's wrong.
Message-Id: <brian-ya02408000R0807000236180001@news.panix.com>
In article <9Zz95.605$lJ1.409424@news.uswest.net>, "Ferk Da Jerk" <shawnball@uswest.net> posted:
> I have this really easy script, but when I run it I get a 500 error. All
> the things are at 777. The script is below. Can any one tell me what's
> wrong with it?
see the troubleshooting guides in the CGI Meta FAQ.
--
brian d foy
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Mongers <URL:http://www.perl.org/>
------------------------------
Date: Sat, 08 Jul 2000 02:20:57 -0500
From: Pete Magdalinos <ComPete12@yahoo.com>
Subject: Re: I can't find what's wrong.
Message-Id: <3966D659.986E2A1@yahoo.com>
I just tried that on my system, and it worked just fine. Check permissions
on /usr/bin/perl .
Maybe one of the directories in your path is not writeable?
PETE
Ferk Da Jerk wrote:
> I have this really easy script, but when I run it I get a 500 error. All
> the things are at 777. The script is below. Can any one tell me what's
> wrong with it?
>
> #!/usr/bin/perl
>
> open (WRITEFILE, ">../../../cgi-bin/practice/other.htm");
> print WRITEFILE "Hello World!";
> close (WRITEFILE);
------------------------------
Date: 8 Jul 2000 15:20:29 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: I can't find what's wrong.
Message-Id: <8k7dbd$37p$1@orpheus.gellyfish.com>
On Fri, 7 Jul 2000 23:54:10 -0700 Ferk Da Jerk wrote:
> I have this really easy script, but when I run it I get a 500 error. All
> the things are at 777. The script is below. Can any one tell me what's
> wrong with it?
>
> #!/usr/bin/perl
>
^ -w
> open (WRITEFILE, ">../../../cgi-bin/practice/other.htm");
You really must check the success of the open
open (WRITEFILE, '>../../../cgi-bin/practice/other.htm')
|| die "Cant open - $!\n";
This will tell you why the open failed.
> print WRITEFILE "Hello World!";
> close (WRITEFILE);
>
/J\
--
yapc::Europe in assocation with the Institute Of Contemporary Arts
<http://www.yapc.org/Europe/> <http://www.ica.org.uk>
------------------------------
Date: Sat, 08 Jul 2000 21:49:23 GMT
From: "Treku" <Treku@w.pl>
Subject: i dont know what to do!!
Message-Id: <DlN95.32817$Qw1.774108@news.tpnet.pl>
Hi
i have very interesting problem (about databases) -
in my base there are a lot of records but the 3rd record (in base it is nu
mber 2) is diffrent from others.
I can mark as deleted or undeleted all records but i cant do it with 3rd r
ecord ? what is wrong?
the 3rd record i suppose is frozen .
the next thing is that if i delete all records from database (and now there
will be no records in database ) and i put some new records (some 6 os 7 r
ecords - it doesn't matter how much, but it has to be more or equal than 3)
the 3rd record will be the same as i wrote higher (i cant mark him as unde
leted, it is still deleted and i cant change it)
I suppose that you understood my problem :)
I don't know how to resolve that.
Treku
Treku@poczta.onet.pl
------------------------------
Date: Fri, 7 Jul 2000 15:53:47 +0200
From: "Patrice Radé" <prade@espace-formation.com>
Subject: ImageMagick with Perl 5.6.0 on Windows NT
Message-Id: <0ll95.1422$Id3.38861@tengri.easynet.fr>
Hello,
I'am a very new developper on PERL language, and i must installe ImageMagick
on PERL 5.6.0 (Windows NT). I have downloaded the binary distribution of
ImageMagick on (www.wizards.dupont.com), and i must compile the module using
PERL with the "makefile.nt" file found with PerlMagick 5.2. In this file, I
must write the path for librairies and include files, and the exemple
proposes :
'LIBS' => '-L...\VisualMagick\bin -L...\VisualMagick\lib ... -lImagick.
I don't have VisualMagick and neither dll Imagick !
How can I find them, or is there an other solution to use ImageMagick with
PERL. ?
Thanck you for your answers and please excuse my bad English.
Patrice Radé
Installation d'ImageMagick :
J'utilise Perl version 5.6.0
J'ai récupéré la distribution binaire (binaries) d'ImageMagick pour Windows
NT sur le site (www.wizards.dupont.com).
Pour compiler le module dans Perl, je me sers du "Makefile.nt" de PerlMagick
5-2. Dans ce fichier il faut indiquer le chemin d'accès des librairies et
include. L'exemple propose :
'LIBS' => '-L...\VisualMagick\bin -L...\VisualMagick\lib ... -lImagick.
Je n'ai ni répertoire VisualMagick, ni dll Imagick. Que dois-je faire ?
Merci de votre aide.
Pb Apache sur Windows NT :
Sous Windows NT, Apache sort très fréquemment en "time out". Sur Linux, pas
de problème. L'un d'entre vous aurait-t'il été confronté au problème ?
Merci de votre aide.
------------------------------
Date: Fri, 07 Jul 2000 11:25:35 -0400
From: Ron Grabowski <ronnie@catlover.com>
Subject: Re: ImageMagick with Perl 5.6.0 on Windows NT
Message-Id: <3965F66F.469D6512@catlover.com>
C:\>ppm install Image-Magick
will work for ActivePerl build 522
------------------------------
Date: Fri, 7 Jul 2000 22:31:07 +0100
From: "B Kemp" <hyagillot@tesco.net>
Subject: Re: ImageMagick with Perl 5.6.0 on Windows NT
Message-Id: <8k7n8c$s2j$1@epos.tesco.net>
>I'am a very new developper on PERL language, and i must installe
ImageMagick
>on PERL 5.6.0 (Windows NT). I have downloaded the binary distribution of
>ImageMagick on (www.wizards.dupont.com), and i must compile the module
using
>PERL with the "makefile.nt" file found with PerlMagick 5.2. In this file, I
<snip>
>How can I find them, or is there an other solution to use ImageMagick with
>PERL. ?
>
>Thanck you for your answers and please excuse my bad English.
Pour compenser je vais faire mon reponse de merde en Francais.
Deja - Si j'ai bien compris tu as deja installe ImageMagick.
Est-ce que tu l'as fait marche sur DOS. Peut-etre il faut commencer a jouer
avec ca pour voir ce que tu peux faire.
Moi, je utilise imagemagick comme ca en perl. On assemble la commande qu'on
peut faire sur DOS (en perl ), puis on fait marcher comme si c'etait en
commande DOS avec `
alors:-
$reponse = ` $commande_qutas_fabrique `;
Il y a des danger si qqn peut mettre les conneries dans la commande qu'on a
fabrique - alors il faut verifies les noms de fichier.
Si il y pas de $reponse, normalment la commande a bien marche, par contre ca
marche pas tres bien tout le temps.
C'est un solution qui est pas ideal, mais c'est vachement plus facile que
l'installation perl.
>Installation d'ImageMagick :
>J'utilise Perl version 5.6.0
>J'ai récupéré la distribution binaire (binaries) d'ImageMagick pour Windows
>NT sur le site (www.wizards.dupont.com).
>Pour compiler le module dans Perl, je me sers du "Makefile.nt" de
PerlMagick
>5-2. Dans ce fichier il faut indiquer le chemin d'accès des librairies et
>include. L'exemple propose :
>'LIBS' => '-L...\VisualMagick\bin -L...\VisualMagick\lib ... -lImagick.
>Je n'ai ni répertoire VisualMagick, ni dll Imagick. Que dois-je faire ?
>Merci de votre aide.
Right. I looked at installing PerlMagick, it needs things I haven't got.
You can make up imagemagick commands in perl and then run them with back
quotes.
$reply=`$made_up_command`
If you get no reply it has (usually) worked.
This is far from an ideal answer, but it can get you up and running.
------------------------------
Date: Mon, 03 Jul 2000 13:40:49 -0400
From: brian@smithrenaud.com (brian d foy)
Subject: Re: Include a C function (or any *.h) in Perl code
Message-Id: <brian-ya02408000R0307001340490001@news.panix.com>
In article <igl0mss8g0s3tqq6v4d53bl3qgai97vu27@4ax.com>, Ambrogio De Lorenzo <ambrogio.delorenzo@art-web.it> posted:
> There is someone that can explain me how I can include C code in Perl
> code?
start with h2xs :)
then see the appropriate man pages. you can get a list of all the
perl man pages with
man perl
--
brian d foy
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Mongers <URL:http://www.perl.org/>
------------------------------
Date: Tue, 04 Jul 2000 15:47:18 -0500
From: Yuandan <ydzhang@iastate.edu>
Subject: include my sub in @INC
Message-Id: <39624D56.EF7217DE@iastate.edu>
Hi,
I have some subroutines under a dir (eg /user/my/require/), the perl is
installed at somewhere else (eg /usr/bin/perl). My question is how can I
include my subroutines in the array @INC? so I can use require to access
them.
Thanks,
Yuadan
------------------------------
Date: Tue, 04 Jul 2000 21:45:40 GMT
From: andrew-johnson@home.com (Andrew Johnson)
Subject: Re: include my sub in @INC
Message-Id: <8Ws85.3983$k5.66467@news1.rdc1.mb.home.com>
In article <39624D56.EF7217DE@iastate.edu>,
Yuandan <ydzhang@iastate.edu> wrote:
> Hi,
> I have some subroutines under a dir (eg /user/my/require/), the perl is
> installed at somewhere else (eg /usr/bin/perl). My question is how can I
> include my subroutines in the array @INC? so I can use require to access
> them.
Please see the entry in perlfaq8:
How do I add a directory to my include path at runtime?
To view this document either do:
man perlfaq8
perldoc perlfaq8
regards,
andrew
--
Andrew L. Johnson http://members.home.net/perl-epwp/
Optimist: The glass is half full.
Pessimist: The glass is half empty.
Engineer: The glass is twice as big as it needs to be.
------------------------------
Date: 4 Jul 2000 22:28:55 GMT
From: efflandt@xnet.com (David Efflandt)
Subject: Re: include my sub in @INC
Message-Id: <slrn8m4p95.ee0.efflandt@efflandt.xnet.com>
On Tue, 04 Jul 2000 15:47:18 -0500, Yuandan <ydzhang@iastate.edu> wrote:
>Hi,
>I have some subroutines under a dir (eg /user/my/require/), the perl is
>installed at somewhere else (eg /usr/bin/perl). My question is how can I
>include my subroutines in the array @INC? so I can use require to access
>them.
>Thanks,
>
>Yuadan
If you are adding your own modules as a user, then just put this somewhere
in your script before you use the modules. This unshifts the path onto
@INC during precompile.
use lib '/user/my/require/';
If you are adding modules system wide, then you would normally put them
within the normal paths.
--
David Efflandt efflandt@xnet.com http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://hammer.prohosting.com/~cgi-wiz/ http://cgi-help.virtualave.net/
------------------------------
Date: Sat, 08 Jul 2000 01:51:53 GMT
From: PAB <theborg@usa.com>
Subject: inserting a list of files and their titles
Message-Id: <3966894D.16E8B6AA@usa.com>
I need to enter a whole dir full of text files in a database. All I
need to do is insert the name and bodyt ino the database.
So table looks like so:
NAME BODY
------------------------
somefile. | contents in here
|
OK simple enough :-)
My question is how can I use a for each statement to enter them all at
once: This will enter the titles but I am not sure how to adapt this to
get the bodies in all at the same time. ANy help would be greatly
appreciated :-)
opendir(DIR, "/mydir/in/here")
@FILES = readdir (DIR);
my $title;
foreach $title(@FILES)
{
my $sql = "insert into mytable values('table', '$body')";
my $sth = $dhh-> prepare($sql);
my $rows = $sth->execute;
}
------------------------------
Date: Sat, 08 Jul 2000 03:36:53 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: inserting a list of files and their titles
Message-Id: <3966A216.A1ABC2C9@rochester.rr.com>
PAB wrote:
>
> I need to enter a whole dir full of text files in a database. All I
> need to do is insert the name and bodyt ino the database.
>
> So table looks like so:
>
> NAME BODY
> ------------------------
> somefile. | contents in here
> |
>
> OK simple enough :-)
>
> My question is how can I use a for each statement to enter them all at
> once: This will enter the titles but I am not sure how to adapt this to
> get the bodies in all at the same time. ANy help would be greatly
> appreciated :-)
>
> opendir(DIR, "/mydir/in/here")
> @FILES = readdir (DIR);
>
> my $title;
> foreach $title(@FILES)
> {
> my $sql = "insert into mytable values('table', '$body')";
> my $sth = $dhh-> prepare($sql);
> my $rows = $sth->execute;
> }
I think your SQL needs a good bit of help. The "insert into" statement
goes something like:
insert into tablename (field1,field2,field2) values(?,?,?)
You need to do the insert into once, then execute it providing values
for the ? placeholders for each row you want to insert. Something like
[untested]:
use DBI;
#your code to get @FILES goes here
my $dbh=DBI->connect(....);
my $sth=$dbh->prepare("insert into mytable (name,body) values(?,?)")
or die $dbh->errstr;
for $title(@FILES){
#code to get values for $name and $body for each record
$sth->execute($name,$body) or die $dbh->errstr;
}
$sth->finish;
$dbh->disconnect;
--
Bob Walton
------------------------------
Date: Sat, 08 Jul 2000 01:21:37 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: inserting a list of files and their titles
Message-Id: <3966BA61.9387AC00@attglobal.net>
Bob Walton wrote:
> > foreach $title(@FILES)
> > {
> > my $sql = "insert into mytable values('table', '$body')";
> > my $sth = $dhh-> prepare($sql);
> > my $rows = $sth->execute;
> > }
>
> I think your SQL needs a good bit of help. The "insert into" statement
> goes something like:
>
> insert into tablename (field1,field2,field2) values(?,?,?)
>
Not the best at SQL here, but IIRC you don't have to specify destination
field names if your entries will go into the default places.
like:
+-----------------------------------+
| data_table |
+----------+-----------+------------+
| Field1 | Field2 | Field3 |
+----------+-----------+------------+
INSERT INTO data_table VALUES ('value1', 'value2', value3') would be
just fine as long as the fileds were to be filled in order and all
columns were accounted for. I tried it on my MySQL toy and it worked
just fine. (when I didn't account for all columns, it complained, but
as long as they were all covered, it was OK)
------------------------------
Date: Sat, 08 Jul 2000 02:17:42 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: inserting a list of files and their titles
Message-Id: <3966C786.1C83EE95@attglobal.net>
PAB wrote:
>
> My question is how can I use a for each statement to enter them all at
> once: This will enter the titles but I am not sure how to adapt this to
> get the bodies in all at the same time. ANy help would be greatly
> appreciated :-)
>
> opendir(DIR, "/mydir/in/here")
> @FILES = readdir (DIR);
>
> my $title;
> foreach $title(@FILES)
> {
> my $sql = "insert into mytable values('table', '$body')";
> my $sth = $dhh-> prepare($sql);
> my $rows = $sth->execute;
> }
This took a few minutes to see clearly. I think because you've named
the array that holds the names of the files (title based on your model)
FILES instead of titles. Thats OK, I just gave it a double take.
The code below is incomplete (I hate SQL, so I left that bit out)
#!/usr/bin/perl -w
use strict;
use DBI;
my $dbh = DBI->connect('connect_stuff_here');
my $dirpath = 'define_your_directory_here';
opendir DIR, $dirpath or die "can't: $! \n";
my @files = readdir (DIR);
chdir $dirpath;
for(@files)
{
local $/ = undef; # allow whole file slurping
open FILERD, $_ or die "Can't open $_: $! \n";
my $body = <FILERD>; #slurp the file into the variable $body
# untested SQL! untested SQL! untested SQL! untested SQL! #
$dbh->do("INSERT INTO test_table VALUES ('$_',
'$body')");
}
$dbh->disconnect();
------------8<-------------------------8<--------------------
It may take some adjustments (I play with MySQL, you may need to chnge
some statments, and add the error check for that insert) but it should
point you in the right direction.
------------------------------
Date: 8 Jul 2000 12:40:47 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: inserting a list of files and their titles
Message-Id: <963058538.27039@itz.pp.sci.fi>
In article <3966C786.1C83EE95@attglobal.net>, Drew Simonis wrote:
>The code below is incomplete (I hate SQL, so I left that bit out)
So let's put your and Bob Walton's partial code together, and throw in
a few tweaks of my own for good measure. This code has been tested,
though I can't guarantee it will always work even in unusual cases
such as those involving perverse file names.
#!/usr/bin/perl -w
use strict;
use DBI;
my $dbh=DBI->connect('your_connect_string_here') or die $DBI::errstr;
my $sth=$dbh->prepare("insert into mytable (name,body) values(?,?)")
or die $dbh->errstr;
my $dirpath = 'your_directory_here';
opendir DIR, $dirpath or die "Can't opendir $dirpath: $!\n";
my @files = readdir (DIR);
chdir $dirpath; # TIMTOWTDI
for my $name (@files) {
next unless -f $name; # skip directories, including . and ..
local $/ = undef;
open FILE, $name or die "Can't open $name: $! \n";
my $body = <FILE>;
$sth->execute($name,$body) or die $dbh->errstr;
}
$sth->finish;
$dbh->disconnect;
__END__
> $dbh->do("INSERT INTO test_table VALUES ('$_',
>'$body')");
This is probably a bad idea. You should either use prepare() or
explicitly pass those values through $dbh->quote().
--
Ilmari Karonen - http://www.sci.fi/~iltzu/
"The screwdriver *is* the portable method." -- Abigail
Please ignore Godzilla and its pseudonyms - do not feed the troll.
------------------------------
Date: Sat, 08 Jul 2000 11:08:43 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: inserting a list of files and their titles
Message-Id: <396743FB.17181922@attglobal.net>
Ilmari Karonen wrote:
> for my $name (@files) {
> next unless -f $name; # skip directories, including . and ..
> local $/ = undef;
> open FILE, $name or die "Can't open $name: $! \n";
> my $body = <FILE>;
>
Nice addition =)
> > $dbh->do("INSERT INTO test_table VALUES ('$_',
> >'$body')");
>
> This is probably a bad idea. You should either use prepare() or
> explicitly pass those values through $dbh->quote().
Tis why I mentioned I use MySQL. With DBD::Mysql, the do() function
automatically calls the quote() function for you and does the insert.
------------------------------
Date: 8 Jul 2000 16:07:08 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: inserting a list of files and their titles
Message-Id: <963072102.18713@itz.pp.sci.fi>
In article <396743FB.17181922@attglobal.net>, Drew Simonis wrote:
>Ilmari Karonen wrote:
[Drew Simonis wrote:]
>> > $dbh->do("INSERT INTO test_table VALUES ('$_',
>> >'$body')");
>>
>> This is probably a bad idea. You should either use prepare() or
>> explicitly pass those values through $dbh->quote().
>
>Tis why I mentioned I use MySQL. With DBD::Mysql, the do() function
>automatically calls the quote() function for you and does the insert.
But it can't handle all situations, can it? do() won't even see the
string until Perl interpolation has mangled it, and if the variables
that were interpolated happen to have strategically placed single
quotes, strange things can happens.
I'm not sure how dangerous that'd be in an INSERT statement, but it
can certainly be a risk in other situations:
my $id = "' OR '' = '";
$dbh->do("DELETE FROM table WHERE ID = '$id'");
Oops..
--
Ilmari Karonen - http://www.sci.fi/~iltzu/
"The screwdriver *is* the portable method." -- Abigail
Please ignore Godzilla and its pseudonyms - do not feed the troll.
------------------------------
Date: Mon, 10 Jul 2000 17:02:59 GMT
From: PAB <theborg@usa.com>
Subject: Re: inserting a list of files and their titles
Message-Id: <396A01D2.F90FB3BC@usa.com>
Thank you. Nice little bit of code. I will be adding some bells and
whistles to strip some chars. You and Drew were of great help.
thanks again,
Peter B.
_________________________________
Ilmari Karonen wrote:
> In article <3966C786.1C83EE95@attglobal.net>, Drew Simonis wrote:
> >The code below is incomplete (I hate SQL, so I left that bit out)
>
> So let's put your and Bob Walton's partial code together, and throw in
> a few tweaks of my own for good measure. This code has been tested,
> though I can't guarantee it will always work even in unusual cases
> such as those involving perverse file names.
>
> #!/usr/bin/perl -w
> use strict;
> use DBI;
>
> my $dbh=DBI->connect('your_connect_string_here') or die $DBI::errstr;
> my $sth=$dbh->prepare("insert into mytable (name,body) values(?,?)")
> or die $dbh->errstr;
>
> my $dirpath = 'your_directory_here';
> opendir DIR, $dirpath or die "Can't opendir $dirpath: $!\n";
>
> my @files = readdir (DIR);
> chdir $dirpath; # TIMTOWTDI
>
> for my $name (@files) {
> next unless -f $name; # skip directories, including . and ..
> local $/ = undef;
> open FILE, $name or die "Can't open $name: $! \n";
> my $body = <FILE>;
>
> $sth->execute($name,$body) or die $dbh->errstr;
> }
>
> $sth->finish;
> $dbh->disconnect;
> __END__
>
> > $dbh->do("INSERT INTO test_table VALUES ('$_',
> >'$body')");
>
> This is probably a bad idea. You should either use prepare() or
> explicitly pass those values through $dbh->quote().
>
> --
> Ilmari Karonen - http://www.sci.fi/~iltzu/
> "The screwdriver *is* the portable method." -- Abigail
> Please ignore Godzilla and its pseudonyms - do not feed the troll.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 3573
**************************************