[19926] in Perl-Users-Digest
Perl-Users Digest, Issue: 2121 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 13 06:05:27 2001
Date: Tue, 13 Nov 2001 03:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1005649507-v10-i2121@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 13 Nov 2001 Volume: 10 Number: 2121
Today's topics:
-M $file on win32 <dump@the-core.net>
Re: -M $file on win32 <Peter.Dintelmann@dresdner-bank.com>
Re: Accessing NT Network Neighbourhood nobull@mail.com
Re: Can I make one perl cgi script work both in linux a <bart.lateur@skynet.be>
Re: converting ^M characters to \n <flavell@mail.cern.ch>
Making an array of records <sasha_lui@yahoo.com>
Re: Making an array of records <usenet@michnet.de>
Re: Making an array of records <s@kspp.de>
Re: Making an array of records <sasha_lui@yahoo.com>
Re: Perl Books <bill.kemp@wire2.com>
Re: Random element from array? (Wiliam Stephens)
Re: Random element from array? <bart.lateur@skynet.be>
scripting microsoft excel in perl? <tnt.wade@verizon.net>
Re: Sending Data to a Printer? <simon.andrews@bbsrc.ac.uk>
Re: Unencoding <mgjv@tradingpost.com.au>
Re: Unencoding <geoff@REMOVETHISgeoffball.net>
Re: Unencoding <geoff@REMOVETHISgeoffball.net>
Why Perl For Database Handling? <annthompson2000USA@yahoo.com>
Re: Why Perl For Database Handling? <usenet@michnet.de>
Re: Why Perl For Database Handling? <bernard.el-hagin@lido-tech.net>
Re: Why Perl For Database Handling? (Logan Shaw)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 13 Nov 2001 10:01:12 +0100
From: Lars Oeschey <dump@the-core.net>
Subject: -M $file on win32
Message-Id: <gao1vt4pml6emo2teve8avnqg4v3sc3lh6@4ax.com>
Hi,
I'm trying to get the age of files on Win32, and have two problems:
1. A file that Windows-Explorer says "last change date 31.10.2001"
gives me with a -M $file a result of 22.92323342 which is too much (-M
should give me tha days since last change, no?)
2. My routine
opendir (SAVE, "$localdir");
while ($datei = readdir (SAVE)) {
if (-f $datei) {
$alter = -M $datei;
print $ datei . ": " . $alter . "\n";
}
}
works fine on files like "text.txt" but not on "text.test.txt",
probably because of the additional dot. The problem seems to be the
opendir routine I guess?
Lars
--
GPZ900R xxMm+2,5Mm http://www.oeschey.de
GS400 xxMm+1,5Mm http://www.the-core.net
------------------------------
Date: Tue, 13 Nov 2001 10:18:16 +0100
From: "Dr. Peter Dintelmann" <Peter.Dintelmann@dresdner-bank.com>
Subject: Re: -M $file on win32
Message-Id: <9sqnrb$ub4@news-1.bank.dresdner.net>
Hi Lars,
"Lars Oeschey" <dump@the-core.net> schrieb im Newsbeitrag
news:gao1vt4pml6emo2teve8avnqg4v3sc3lh6@4ax.com...
[skip]
> opendir (SAVE, "$localdir");
> while ($datei = readdir (SAVE)) {
> if (-f $datei)
> $alter = -M $datei;
> print $ datei . ": " . $alter . "\n";
> }
> }
>
> works fine on files like "text.txt" but not on "text.test.txt",
> probably because of the additional dot. The problem seems to be the
> opendir routine I guess?
did you keep in mind that readdir() returns the file name
without the directory?
Thus I suspect you wanted to type
if (-f "$localdir/$datei") { ... }
instead of
if (-f $datei) { ... }
Is this of any help to you?
Peter
p.s.: have a look at the special "_" handle when doing multiple
file tests.
>
>
> Lars
> --
> GPZ900R xxMm+2,5Mm http://www.oeschey.de
> GS400 xxMm+1,5Mm http://www.the-core.net
------------------------------
Date: 12 Nov 2001 20:17:15 +0000
From: nobull@mail.com
Subject: Re: Accessing NT Network Neighbourhood
Message-Id: <u9lmhbknty.fsf@wcl-l.bham.ac.uk>
"S Warhurst" <s.warhurst@rl.ac.uk> writes:
> How can I access a network drive (NT), in this case - to create a file?
>
> I am trying:
>
> open(FILE, "\\\\servername\\directory\\file.txt")
That is attempting to open the file for reading. Opening files for
reading does not create them if they don't already exist. For an
explaination of how to open files in other modes with the open()
function see the documentation of the open() function.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 13 Nov 2001 10:47:04 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Can I make one perl cgi script work both in linux and in windows?
Message-Id: <d5u1vto9r6h1gr99pi3v40fr8l92jus4i9@4ax.com>
Shi Jin wrote:
>in linux , the first line should be
>#!/usr/bin/perl
>But in windows, it should be
>#!E:\cygwin\bin\perl.exe
>How can I make it work in both systems?
You can modify the shebang lines. I use a script to take scripts from
one directory and write them to another while doing some small changes,
such as the shebang line, and root directory of the data file tree; "use
lib (libdir)" is commonly a third.
But someone here recently drew my attention to the fact that in the
Apache configuration file, you can instruct it to ignore the shebang
line. See
<http://httpd.apache.org/docs-2.0/mod/core.html#scriptinterpretersource>.
--
Bart.
------------------------------
Date: Tue, 13 Nov 2001 11:38:39 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: converting ^M characters to \n
Message-Id: <Pine.LNX.4.30.0111131117520.8610-100000@lxplus023.cern.ch>
On Nov 12, J.B. Moreno inscribed on the eternal scroll:
[..snipped..]
Thanks for helping to clear this issue up.
> OK. Let me say that I think it'd be nice if there was some simple and
> standard (other than 0x0?) for the ASCII values CR and LF.
Well, in ASCII[1] you have \015 and \x0D and \cM, whichever the
programmer is most comfortable with in context; or you can export the
Socket.pm definitions as was already commented.
So the Perl principle is satisfied: there's already more than one way
to do it ;-)
cheers
[1] I get no practice these days in programming on EBCDIC platforms.
CGI.pm has some code to cover that situation in the particular
instance of communicating over what appears to be an EBCDIC CGI
interface with an HTTPD. But, on the other hand, if you were driving
a cross-platform socket then you'd presumably be handling ASCII data
anyway.
------------------------------
Date: Tue, 13 Nov 2001 10:53:47 +0100
From: "Sasha" <sasha_lui@yahoo.com>
Subject: Making an array of records
Message-Id: <9sqpb6$m6$1@newstoo.ericsson.se>
Hi
I was wondering if some one could help me to make an array / hash of
records. I have an input variables that contains a phone number like :
$new_phon_nr =(
"Peter" =>"46978955",
)
And i want to have an hash/array that keep this information with an index,
like:
$phon_list{$index}=$new_phon_nr ;
And each time i receive a new phon number i want to save it in the list and
increase the index by one so each index contain one phone number. and i
alwayes want to be able to know the latest index number.
Hope you can tell me how to make it, if you know a better way to do it i
will be glad to see it.
Thanks in advance Sasha
------------------------------
Date: Tue, 13 Nov 2001 11:11:30 +0100
From: Michael Velten <usenet@michnet.de>
Subject: Re: Making an array of records
Message-Id: <ikrqs9.g62.ln@conscious.reno.de>
* Sasha <sasha_lui@yahoo.com> in clpm:
> And i want to have an hash/array that keep this information with an
> index, like:
>
> $phon_list{$index}=$new_phon_nr ;
>
> And each time i receive a new phon number i want to save it in the
> list and increase the index by one so each index contain one phone
> number. and i alwayes want to be able to know the latest index number.
Assuming that $index is a consecutive number you could use an array for
indexing and each member of it is a hash containing the name as its key
and the phone number as its value. So you can easily get the last index
with $#array.
Michael
------------------------------
Date: Tue, 13 Nov 2001 11:43:06 +0100
From: Stefan Etschberger <s@kspp.de>
Subject: Re: Making an array of records
Message-Id: <3BF0F93A.4020702@kspp.de>
Sasha wrote:
>Hi
>
>I was wondering if some one could help me to make an array / hash of
>records. I have an input variables that contains a phone number like :
>
>$new_phon_nr =(
>"Peter" =>"46978955",
>)
>
>And i want to have an hash/array that keep this information with an index,
>like:
>
>$phon_list{$index}=$new_phon_nr ;
>
>And each time i receive a new phon number i want to save it in the list and
>increase the index by one so each index contain one phone number. and i
>alwayes want to be able to know the latest index number.
>
# filling...
push @{ $phon_list }, \$new_phon_nr;
# accessing...
$phon_list->[$index];
# number of elements (-1)
$#{ $phon_list };
check out manpages perldsc, perlref
Stefan
------------------------------
Date: Tue, 13 Nov 2001 11:50:19 +0100
From: "Sasha" <sasha_lui@yahoo.com>
Subject: Re: Making an array of records
Message-Id: <9sqsl7$940$1@newstoo.ericsson.se>
Thanks for replaying my mail.
I am new in perl programming. I have wrote these code to do my job but i am
getting an error saying :
(
my" variable $myindex masks earlier declaration in same scope at myhash.pl
line 4.
Can't declare array element in my at myhash.pl line 4, near "]="
Execution of myhash.pl aborted due to compilation errors.
)
And my Source code is
#!/usr/local/bin/perl -w
my $myindex = 0;
my $new_phon_nr;
my $phon_list[$myindex]={};
$new_phon_nr =(
"Peter" =>"46978955",
);
for (1 .. 5){
$index = $_;
$phon_list[$myindex]=$new_phon_nr ;
}
I want also ask how can i read the array if i want to read these array
Regards Sasha
------------------------------
Date: Tue, 13 Nov 2001 10:04:06 -0000
From: "W K" <bill.kemp@wire2.com>
Subject: Re: Perl Books
Message-Id: <Tg6I7.122$yw1.1272@news.uk.colt.net>
> these are good, some are OK, but many aren't worth your money. Tom
> Christiansen maintains a list of these books, some with extensive
> reviews, at http://www.perl.com/perl/critiques/index.html .
"Sorry, but the page you requested is unavailable."
------------------------------
Date: 13 Nov 2001 01:17:52 -0800
From: wil@fbagroup.co.uk (Wiliam Stephens)
Subject: Re: Random element from array?
Message-Id: <39e3e00a.0111130117.19ef3906@posting.google.com>
Thanks for all your help guys. I'm still having problems, however.
I've now got the following (modified from your responses) code:
$| = 1;
use CGI;
$query = CGI::new();
print $query->header();
@allhtml = qw(index.apricot.html
index.butter.html
index.garden.html
index.greek.html
index.maple.html
index.raspberry.html
index.strawberry.html
index.natural.html
);
my $randhtml = $allhtml[int rand @allhtml];
open (HTMLDAT, "</home/fba/beta.rachelsorganic.co.uk/$randhtml");
@html = <HTMLDAT>;
close HTMLDAT;
print @html;
Which still doesn't work. The error message I get when trying to run
this from a telnet window is:
Illegal variable name.
However when I run perl -c index.cgi it tells me that my syntax is OK.
Unfortunately my web host is running Perl version 5.005_03. They are
planning an upgrade before Christmass.
I just can't get my head around this problem. It seems like such a
simple script. Does anyone else see the problem here? Have I
olverlooked something?
Cheers
Wil
------------------------------
Date: Tue, 13 Nov 2001 10:26:12 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Random element from array?
Message-Id: <r7t1vtsjchchh5i9uekpj1c5avqit308pa@4ax.com>
Wiliam Stephens wrote:
>The error message I get when trying to run
>this from a telnet window is:
>
> Illegal variable name.
>
>However when I run perl -c index.cgi it tells me that my syntax is OK.
How do you run it in telnet? Do you use
perl index.cgi
or
./index.cgi
?
Because maybe, just maybe, your shebang line is pointing to the wrong
perl binary, maybe even perl4.
--
Bart.
------------------------------
Date: Tue, 13 Nov 2001 05:42:46 GMT
From: sniper <tnt.wade@verizon.net>
Subject: scripting microsoft excel in perl?
Message-Id: <qp2I7.7199$vM6.239808@typhoon1.gnilink.net>
Please forgive me, but I am brand new to linux and perl (but already love
them and want to learn!). I was wondering if there are any sites with
simple examples on how to script microsoft excel in perl? Thanks in
advance.
sniper
------------------------------
Date: Tue, 13 Nov 2001 10:52:56 +0000
From: Simon Andrews <simon.andrews@bbsrc.ac.uk>
Subject: Re: Sending Data to a Printer?
Message-Id: <3BF0FB88.F89D0A4E@bbsrc.ac.uk>
"Mike Mackay [Ultrafusion]" wrote:
>
> Hi,
> Is it at all possible to send the output of a perl programme, for
> example maybe some contents from a database, to a printer?
>
> I'm using Win98 with ActiveState Perl....incase that makes a difference,
> which I'm sure it does.
If you're only wanting to print text then you can do this by writing the
output to a file, then;
To send to a local printer;
system('copy this.txt PRN');
or to a network printer;
system('copy this.txt \\Server\Printer\');
Where PRN is equivalent to LPT1, and you can replace Server\Printer with
whatever is sensible on your system.
Hope this helps
TTFN
Simon.
------------------------------
Date: Tue, 13 Nov 2001 19:35:08 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Unencoding
Message-Id: <slrn9v1mps.f5j.mgjv@martien.heliotrope.home>
On Tue, 13 Nov 2001 07:57:27 GMT,
Geoff <geoff@REMOVETHISgeoffball.net> wrote:
> "Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
> news:slrn9v1i5d.f5j.mgjv@martien.heliotrope.home...
>> On Tue, 13 Nov 2001 05:33:16 GMT,
>> Geoff <geoff@REMOVETHISgeoffball.net> wrote:
>> > "Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
>> > news:slrn9v0jgl.2q5.mgjv@verbruggen.comdyn.com.au...
>> >
>> >> > $code =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>> >
>> >> Has anyone tried this approach on EBCDIC machines? Or the reverse with
>> >>
>> >> sprintf "%%%02x", ord $char
>> >>
>> >> Martien
>> >
>> > What's an example of a system that would use this? Windows, Unix, and
>> > Solaris all use ASCII (not sure about Macs, but I think they do too).
>>
>> $ man perlport
>> [snip]
>> EBCDIC Platforms
>>
>> Recent versions of Perl have been ported to platforms such
>> as OS/400 on AS/400 minicomputers as well as OS/390,
>> VM/ESA, and BS2000 for S/390 Mainframes. Such computers
>> use EBCDIC character sets internally (usually Character
>> Code Set ID 0037 for OS/400 and either 1047 or POSIX-BC
>> for S/390 systems). On the mainframe perl currently works
>> under the "Unix system services for OS/390" (formerly
>> known as OpenEdition), VM/ESA OpenEdition, or the BS200
>> POSIX-BC system (BS2000 is supported in perl 5.6 and
>> greater). See the perlos390 manpage for details.
>> [snip]
>>
>> Martien
>
> Duly noted, but how many people are going to be:
>
> 1) Using these computers? (they look like servers)
Many. Especially the AS/400 is very popular. OS/390 machines are
also quite frequently used.
> 2) Using these computers to browse the internet?
What does this have to do with browsing? decoding things like these
happen on servers as well.
> 3) Actually visit the site which is using theis Perl script?
Huh?
Who cares how many people do or don't visit that site? And what exactly
is the point you're trying to make?
I asked a question about the portability of that particular piece of
code. If you can't answer that question, what point are you trying to
make?
Are you also suggesting that the people who are putting the work into
porting Perl to these platforms, or any other EBCDIC platforms are
wasting their time, because _you_ don't think they'll be used frequently
enough?
Martien
--
|
Martien Verbruggen | Freudian slip: when you say one thing
| but mean your mother.
|
------------------------------
Date: Tue, 13 Nov 2001 10:04:16 GMT
From: "Geoff" <geoff@REMOVETHISgeoffball.net>
Subject: Re: Unencoding
Message-Id: <Ae6I7.47896$5e2.8273118@news1.telusplanet.net>
"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrn9v1mps.f5j.mgjv@martien.heliotrope.home...
[snipped]
> > Duly noted, but how many people are going to be:
> >
> > 1) Using these computers? (they look like servers)
>
> Many. Especially the AS/400 is very popular. OS/390 machines are
> also quite frequently used.
> > 2) Using these computers to browse the internet?
>
> What does this have to do with browsing? decoding things like these
> happen on servers as well.
Maybe you should read my original post.
> > > [for] turning all encoded characters in the URL (when submitted in
> > > a form) into their respective unencoded characters.
I was going to use it on a perl script, which received data from a form. So
in actuality, it had everything to do with browsing.
> > 3) Actually visit the site which is using theis Perl script?
>
> Huh?
>
> Who cares how many people do or don't visit that site? And what exactly
> is the point you're trying to make?
Well, seeing as how the original question was about unencoding data sent
from a form to a Perl script, I think it has a lot to do with who visits the
site. I was saying, how many people who use these computers are going to
end up going to this site (implying that out of all the sites on the
internet, what would be the odds that they would end up going there...).
> I asked a question about the portability of that particular piece of code.
Maybe you should re-read the original question (if you even read it in the
first place).
> If you can't answer that question, what point are you trying to make?
I was asking the question, not answering it.
> Are you also suggesting that the people who are putting the work into
> porting Perl to these platforms, or any other EBCDIC platforms are
> wasting their time, because _you_ don't think they'll be used frequently
> enough?
Look, "buddy." Before you go putting words in my mouth, I think you have to
practice your reading skills. I didn't suggest that porting Perl to an
EBCDIC platform is a waste of time at *any* point in my post, so don't even
attempt to imply that I did.
I was asking *you* if they'd be used frequently enough by my viewers to
bother supporting anything non-ASCII. Obviously, it was unclear to you, so
I'll say it in simpler terms:
How many people are going to not only use these computers to surf the web,
but also happen to go to my page?
Based on your defensive outburst there, I'm thinking: not many.
The minority group often gets defensive (human nature is to become defensive
when overwhelmed), and EBCDIC is a minority to ASCII.
You, sir, are EBCDIC.
"Of course, that's just my opinion. I could be wrong."
Geoff
------------------------------
Date: Tue, 13 Nov 2001 10:11:21 GMT
From: "Geoff" <geoff@REMOVETHISgeoffball.net>
Subject: Re: Unencoding
Message-Id: <dl6I7.47920$5e2.8276978@news1.telusplanet.net>
"Geoff" <geoff@REMOVETHISgeoffball.net> wrote in message
news:Ae6I7.47896$5e2.8273118@news1.telusplanet.net...
>
> "Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
> news:slrn9v1mps.f5j.mgjv@martien.heliotrope.home...
>
> [snipped]
>
> > > Duly noted, but how many people are going to be:
> > >
> > > 1) Using these computers? (they look like servers)
> >
> > Many. Especially the AS/400 is very popular. OS/390 machines are
> > also quite frequently used.
>
> > > 2) Using these computers to browse the internet?
> >
> > What does this have to do with browsing? decoding things like these
> > happen on servers as well.
>
> Maybe you should read my original post.
>
> > > > [for] turning all encoded characters in the URL (when submitted in
> > > > a form) into their respective unencoded characters.
>
> I was going to use it on a perl script, which received data from a form.
So
> in actuality, it had everything to do with browsing.
>
> > > 3) Actually visit the site which is using theis Perl script?
> >
> > Huh?
> >
> > Who cares how many people do or don't visit that site? And what exactly
> > is the point you're trying to make?
>
> Well, seeing as how the original question was about unencoding data sent
> from a form to a Perl script, I think it has a lot to do with who visits
the
> site. I was saying, how many people who use these computers are going to
> end up going to this site (implying that out of all the sites on the
> internet, what would be the odds that they would end up going there...).
>
> > I asked a question about the portability of that particular piece of
code.
>
> Maybe you should re-read the original question (if you even read it in the
> first place).
>
> > If you can't answer that question, what point are you trying to make?
>
> I was asking the question, not answering it.
>
> > Are you also suggesting that the people who are putting the work into
> > porting Perl to these platforms, or any other EBCDIC platforms are
> > wasting their time, because _you_ don't think they'll be used frequently
> > enough?
>
> Look, "buddy." Before you go putting words in my mouth, I think you have
to
> practice your reading skills. I didn't suggest that porting Perl to an
> EBCDIC platform is a waste of time at *any* point in my post, so don't
even
> attempt to imply that I did.
>
> I was asking *you* if they'd be used frequently enough by my viewers to
> bother supporting anything non-ASCII. Obviously, it was unclear to you,
so
> I'll say it in simpler terms:
>
> How many people are going to not only use these computers to surf the web,
> but also happen to go to my page?
>
> Based on your defensive outburst there, I'm thinking: not many.
>
> The minority group often gets defensive (human nature is to become
defensive
> when overwhelmed), and EBCDIC is a minority to ASCII.
>
> You, sir, are EBCDIC.
Upon re-reading: with all the people these days who claim everything is
*ist, I'll clear things up. I'm suggesting you're too defensive. So don't
go making accusations of anything else [which was NOT intended].
> "Of course, that's just my opinion. I could be wrong."
>
> Geoff
>
>
------------------------------
Date: Tue, 13 Nov 2001 05:14:15 -0500
From: "Ann Thompson" <annthompson2000USA@yahoo.com>
Subject: Why Perl For Database Handling?
Message-Id: <9sqr1n$n71$1@slb0.atl.mindspring.net>
I'm a SQL person, but my boss wants me to do this in Perl. I'm thinking of
resigning.
To simplify problem:
borrower file: bnum, bname, bphone
book file: ISBN, author, title, pub, cost, year
bb file: bnum, ISBN, date
In SQL, I do:
SELECT borrower.bname, bb.date, book.author, book.title
FROM borrower, book, bb
WHERE borrower.bnum = "123" and
borrower.bnum = bb.bnum and
bb.ISBN = book.ISBN
What need to be retrieved:
Borrower number: 123
Borrower name: Adam
Borrow date: November 10, 2001
Book author: "Perlly Smart"
Book title: "Perl Is The Best?"
I'm spending a lot of time figuring this out at www.perl.com, but can't find
any helpful topic on this.
Please help before I quite my job. Any advice will be appreciated.
------------------------------
Date: Tue, 13 Nov 2001 11:14:16 +0100
From: Michael Velten <usenet@michnet.de>
Subject: Re: Why Perl For Database Handling?
Message-Id: <oprqs9.g62.ln@conscious.reno.de>
* Ann Thompson <annthompson2000USA@yahoo.com> in clpm:
> I'm a SQL person, but my boss wants me to do this in Perl.
What about using the DBI module?
Michael
------------------------------
Date: 13 Nov 2001 10:14:27 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: Why Perl For Database Handling?
Message-Id: <slrn9v1vl7.3il.bernard.el-hagin@gdndev25.lido-tech>
On Tue, 13 Nov 2001 05:14:15 -0500, Ann Thompson <annthompson2000USA@yahoo.com>
wrote:
> I'm a SQL person, but my boss wants me to do this in Perl. I'm thinking of
> resigning.
>
> To simplify problem:
>
> borrower file: bnum, bname, bphone
> book file: ISBN, author, title, pub, cost, year
> bb file: bnum, ISBN, date
>
> In SQL, I do:
>
> SELECT borrower.bname, bb.date, book.author, book.title
>
> FROM borrower, book, bb
>
> WHERE borrower.bnum = "123" and
> borrower.bnum = bb.bnum and
> bb.ISBN = book.ISBN
>
> What need to be retrieved:
>
> Borrower number: 123
> Borrower name: Adam
> Borrow date: November 10, 2001
> Book author: "Perlly Smart"
> Book title: "Perl Is The Best?"
>
> I'm spending a lot of time figuring this out at www.perl.com, but can't find
> any helpful topic on this.
There are modules that will help you with this. Check out:
http://search.cpan.org/
> Please help before I quite my job. Any advice will be appreciated.
Quite.
Cheers,
Bernard
------------------------------
Date: 13 Nov 2001 05:02:34 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Why Perl For Database Handling?
Message-Id: <9squka$qgn$1@charity.cs.utexas.edu>
In article <9sqr1n$n71$1@slb0.atl.mindspring.net>,
Ann Thompson <annthompson2000USA@yahoo.com> wrote:
>I'm a SQL person, but my boss wants me to do this in Perl. I'm thinking of
>resigning.
>
>In SQL, I do:
>
>SELECT borrower.bname, bb.date, book.author, book.title
>
>FROM borrower, book, bb
>
>WHERE borrower.bnum = "123" and
> borrower.bnum = bb.bnum and
> bb.ISBN = book.ISBN
>
>What need to be retrieved:
>
>Borrower number: 123
>Borrower name: Adam
>Borrow date: November 10, 2001
>Book author: "Perlly Smart"
>Book title: "Perl Is The Best?"
Fear not, Perl will not force you to use something weird. It uses SQL
just like everybody else, and it has pretty decent for doing so. So
you can construct the query, and then use Perl to do minor processing
on the results:
use DBI;
$db_type = 'mysql'; # or oracle or whatever
$database = 'booksdb';
$hostname = 'dbhost';
$port = '1234';
$user = 'joebob';
$password = 'itsasecret';
$dsn = "DBI:$db_type:database=$database;host=$hostname;port=$port";
$database_handle = DBI->connect ($dsn, $user, $password);
$sql = '
select
borrower.bname as name,
bb.date as date,
book.author as author,
book.title as title
from borrower, book, bb
where
borrower.bnum = ?
and borrower.bnum = bb.num
and bb.ISBN = book.ISBN
';
$statement_handle = $database_handle->prepare ($sql);
foreach my $borrower_number (123, 127, 699)
{
$statement_handle->execute ($borrower_number);
while ($hash_reference = $statement_handle->fetchrow_hashref)
{
print "Borrower number: $borrower_number\n";
print "Borrower name: $hash_reference->{name}\n";
print "Borrow date: $hash_reference->{date}\n";
print "Book author: $hash_reference->{author}\n";
print "Book title: $hash_reference->{title}\n";
print "\n";
}
$statement_handle->finish;
}
$database_handle->disconnect;
A couple of notes:
1) The prepare() method on a database handle allows one to parse SQL
before certain values have been included in the SQL; they can be
substituted in at the time you execute it. This is nice because
the SQL doesn't have to be repeatedly parsed if you do several
similar queries over time.
2) The above leaves out some error checking, but if you check the DBI
documentation at http://search.cpan.org/search?dist=DBI , it will
explain what to do.
3) Once you know a little Perl, it's not hard to construct SQL on the
fly, so that you could take that entire list of borrower numbers
and build an SQL statement with "borrower.bnum in (123,127,699)" in
it. (Assuming you wanted to do that.)
4) The fetchrow_hashref() method on a statement handle returns
a hash reference. A reference is sort of the Perl equivalent of a
smart pointer. A hash is the Perl terminology for an associative
array. The keys in the associative array are the field names
returned in each row of the query. The values are the actual data
returned by the query.
Have fun.
- Logan
--
"In order to be prepared to hope in what does not deceive,
we must first lose hope in everything that deceives."
Georges Bernanos
------------------------------
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 2121
***************************************