[20030] in Perl-Users-Digest
Perl-Users Digest, Issue: 2225 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 28 06:05:51 2001
Date: Wed, 28 Nov 2001 03:05:07 -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: <1006945507-v10-i2225@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 28 Nov 2001 Volume: 10 Number: 2225
Today's topics:
Re: Filehandle Comparing? <Tassilo.Parseval@post.rwth-aachen.de>
getting front and back location of an array <hkyeung9@ie.cuhk.edu.hk>
Re: getting front and back location of an array <bernard.el-hagin@lido-tech.net>
Re: getting front and back location of an array <perl@cableone.net>
Re: getting front and back location of an array <bernard.el-hagin@lido-tech.net>
Re: getting front and back location of an array <perl@cableone.net>
Re: getting front and back location of an array <bernard.el-hagin@lido-tech.net>
HERE documents and setuid programs <m.f.z.abdel-messeh@open.ac.uk>
Re: How to implement "peres unbiasing" in perl. <goldbb2@earthlink.net>
How to split file on max number of lines (David Kenneally)
Re: How to split file on max number of lines <uri@stemsystems.com>
Re: How to trap calls to undefined procedures at compil <bart.lateur@pandora.be>
Re: Internal Server Error <username@this.is.a.trap.graffl.net>
Re: Internal Server Error <username@this.is.a.trap.graffl.net>
is rename atomic? (Joachim Ziegler)
Re: Newbie Help... <chrisw_63@hotmail.com>
Perl cgi-bin and Apache <ezio@toglimi.comune.grosseto.it>
Re: PERL DBI ODBC... MS SQL *argh* <simon.oliver@umist.ac.uk>
syswrite on closed socket? (winter7)
Re: Thread Question <rss@idiom.com>
Re: Using CGI.pm to obtain a list of params <wsegrave@mindspring.com>
Win32::ODBC => generating a list of hashes from the que <zoltan.kandi@tellabs.com>
Re: Win32::ODBC => generating a list of hashes from the <bernard.el-hagin@lido-tech.net>
Re: Win32::ODBC => generating a list of hashes from the <zoltan.kandi@tellabs.com>
Re: Win32::ODBC => generating a list of hashes from the <bernard.el-hagin@lido-tech.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 28 Nov 2001 11:55:34 +0100
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Filehandle Comparing?
Message-Id: <9u2fr6$aaq$07$1@news.t-online.com>
On 27 Nov 2001 23:49:57 -0800, Kit wrote:
> Hello, all,
>
> I am opening a folder in which holds just .dat files. I set the
> filehandle DATFILE for all of the .dat files (or, more precisely, each
> of them).
> open REGFILE, "$ENV{'BASEFOLDER'}/$ENV{'DATFILES'}/";
> my ($email,$password,$name) = <REGFILE>;
>
> Right now I need to compare one variable, $address, to the name of
> each dat file. How do I do this? I tried:
> if REGFILE eq $address {
> #Commands
> }
> But perl did not seem to want the filehandle. What can I do?
The filehandle is not a string. A filehandle is (non-technically
speaking) a thing associated with a file that enables perl to do
different things with it (write to, read from etc.). You will have to
store the second argument to open in a variable and check this variable
(containing a string) with $address. As far as I know there is no
Perl-function that returns the filename belonging to a filehandle. Bear
in mind that a filehandle does not have to represent a file on your
disk. It can also be a socket or an anonymous file (such as what
IO::File::new_tmpfile creates). These things don't even have a filename.
Tassilo
--
Teachers have class.
------------------------------
Date: Wed, 28 Nov 2001 16:10:31 -0800
From: "Kit" <hkyeung9@ie.cuhk.edu.hk>
Subject: getting front and back location of an array
Message-Id: <9u25mo$d4h$1@eng-ser1.erg.cuhk.edu.hk>
Hello,
I want to get the value of the front and the back of a location of an
array, then how can i do?
eg. @field=(boy,apple,girl,dog,apple,bird);
for(@field){
if ($_ =/apple/)
{
#then i want to show the front of it:boy or dog
#then i want to show the back of it:girl or bird
}
}
Thank you~
------------------------------
Date: 28 Nov 2001 08:40:28 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: getting front and back location of an array
Message-Id: <slrna09bku.qsr.bernard.el-hagin@gdndev25.lido-tech>
On Wed, 28 Nov 2001 16:10:31 -0800, Kit <hkyeung9@ie.cuhk.edu.hk> wrote:
> Hello,
> I want to get the value of the front and the back of a location of an
> array, then how can i do?
> eg. @field=(boy,apple,girl,dog,apple,bird);
> for(@field){
> if ($_ =/apple/)
> {
> #then i want to show the front of it:boy or dog
> #then i want to show the back of it:girl or bird
> }
> }
I think you mean that you want the elements before or after
the element that matches your regex. If so, here's one of
many ways. It's not very perlish, but it's easy to follow.
#!/usr/bin/perl -w
use strict;
my @field = qw (boy apple girl dog apple bird);
for ( my $i = 0; $i < @field; $i++ ){
if ( $field[$i] eq 'apple' ){
$field[$i - 1] and print "Back = $field[$i - 1]\n";
$field[$i + 1] and print "Front = $field[$i + 1]\n";
}
}
Cheers,
Bernard
------------------------------
Date: Wed, 28 Nov 2001 02:41:34 -0600
From: "Jason Gray" <perl@cableone.net>
Subject: Re: getting front and back location of an array
Message-Id: <u098qbi37bnd9d@corp.supernews.com>
Just do:
@field = ('boy','apple','girl','dog','apple','bird');
print "$field[0]" . "$field[5]\n";
Regards,
Jason Gray
"Just Another Perl Programmer"
------------------------------
Date: 28 Nov 2001 08:46:44 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: getting front and back location of an array
Message-Id: <slrna09c0l.qsr.bernard.el-hagin@gdndev25.lido-tech>
On Wed, 28 Nov 2001 02:41:34 -0600, Jason Gray <perl@cableone.net> wrote:
> Just do:
>
> @field = ('boy','apple','girl','dog','apple','bird');
> print "$field[0]" . "$field[5]\n";
If you're joking you should make this apparent since the OP (who
is not a native speaker of English) might not understand your
intent and actually use your "solution".
If you're not joking then please stop using "Just Another Perl
Programmer" as a tag line.
Cheers,
Bernard
------------------------------
Date: Wed, 28 Nov 2001 02:59:48 -0600
From: "Jason Gray" <perl@cableone.net>
Subject: Re: getting front and back location of an array
Message-Id: <u099sb64ei4eb4@corp.supernews.com>
"Bernard El-Hagin" <bernard.el-hagin@lido-tech.net> wrote in message
news:slrna09c0l.qsr.bernard.el-hagin@gdndev25.lido-tech...
> On Wed, 28 Nov 2001 02:41:34 -0600, Jason Gray <perl@cableone.net> wrote:
> > Just do:
> >
> > @field = ('boy','apple','girl','dog','apple','bird');
> > print "$field[0]" . "$field[5]\n";
>
>
> If you're joking you should make this apparent since the OP (who
> is not a native speaker of English) might not understand your
> intent and actually use your "solution".
>
>
> If you're not joking then please stop using "Just Another Perl
> Programmer" as a tag line.
>
>
> Cheers,
> Bernard
That was intended to be an offset of a joke. I can addin some code if you
would like.
Regards,
Jason
------------------------------
Date: 28 Nov 2001 09:25:27 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: getting front and back location of an array
Message-Id: <slrna09e99.qsr.bernard.el-hagin@gdndev25.lido-tech>
On Wed, 28 Nov 2001 02:59:48 -0600, Jason Gray <perl@cableone.net> wrote:
> "Bernard El-Hagin" <bernard.el-hagin@lido-tech.net> wrote in message
> news:slrna09c0l.qsr.bernard.el-hagin@gdndev25.lido-tech...
>> On Wed, 28 Nov 2001 02:41:34 -0600, Jason Gray <perl@cableone.net> wrote:
>> > Just do:
>> >
>> > @field = ('boy','apple','girl','dog','apple','bird');
>> > print "$field[0]" . "$field[5]\n";
>>
>>
>> If you're joking you should make this apparent since the OP (who
>> is not a native speaker of English) might not understand your
>> intent and actually use your "solution".
>>
>>
>> If you're not joking then please stop using "Just Another Perl
>> Programmer" as a tag line.
>
>
> That was intended to be an offset of a joke. I can addin some code if you
> would like.
I don't really care whether you "addin" some code or not, but
if you are making a joke (especially a bad one) you should make
that clear. More so in this case since the OP might not get it
being both a newbie and a non-native speaker of English.
Cheers,
Bernard
------------------------------
Date: Wed, 28 Nov 2001 10:00:02 +0000
From: Maged Abdel-Messeh <m.f.z.abdel-messeh@open.ac.uk>
Subject: HERE documents and setuid programs
Message-Id: <3C04B5A2.54BEE87B@open.ac.uk>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<tt>Dear All,</tt><tt></tt>
<p><tt>I wonder if you can help me ... I am trying to run a perl script
which calls the system command rwall which in turn uses the concept of
HERE documents as its input. Also the perl script is a setuid so
it has to avoid taintness. In my program I have tried something like:</tt><tt></tt>
<p><tt>exec "/usr/sbin/rwall", @remotes, "<<-END\nThis is a warning\nEND";</tt>
<br><tt># This is not tainted but rwall thinks that <<-END is another
machine</tt><tt></tt>
<p><tt>exec "/usr/sbin/rwall @remotes <<-END\nThis is a warning\nEND";</tt>
<br><tt># This is tainted .. gives Insecure dependency</tt><tt></tt>
<p><tt>where @remotes is a list of remote machines</tt><tt></tt>
<p><tt>Regards,</tt><tt></tt>
<p><tt>Maged Messeh</tt></html>
------------------------------
Date: Wed, 28 Nov 2001 03:18:13 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: How to implement "peres unbiasing" in perl.
Message-Id: <3C049DC4.68438FF3@earthlink.net>
Benjamin Goldberg wrote:
>
> I'm trying to implement a really funky algorithm known as "Peres
> unbiasing."
>
> I couldn't find the original paper online, but did find it described
> in the paper "Tossing a Biased Coin" by Michael Mitzenmacher, [which
> is available at http://www.fas.harvard.edu/~libcs124/CS/coinflip3.pdf
> and at http://www.fas.harvard.edu/~libcs124/CS/coinflip3.ps ], as
> something called the "Advanced Multi-Level Strategy."
>
> I understand the basic "Multi-Level Strategy," [also described in that
> paper] but the "Advanced" one is hurting my brane.
Hmm, I *think* I've found my problem, or part of it.
With the advanced strategy, each level recieves exactly half as many
input bits as the prior level. At each level, the basic multi-level
strategy is applied to those input bits to get output bits.
Obviously, if the basic multi-level strategy averages X bits/flip then
the advanced strategy will get X * ( 1 + 1/2 + 1/4 + 1/8 + ... ) bits
per flip... that is, twice as many bits per flip, or half as many flips
per bit.
Considering that with my implementation of mls, I average about 3 flips
per bit... 1.5 does seem to make some sense.
But the paper implies that I should be able to get ONE flip per bit...
The problem, then, is that to get 1 flip per bit with amls, I need to
get 2 flips per bit with mls... here's mls:
my ($heads, $tails) = (0,0);
sub get_bit {
my ($coin,$mask);
do {
($coin = coinflip()) ? ++$heads : ++$tails;
$mask = $heads & $tails;
} until($mask);
$heads &= ~$mask; $tails &= ~$mask;
$coin;
}
Experimentation shows that this requires 3 coinflips per returned bit.
Logic *seems* to indicate that it should consume 1 / (1/4+1/8+1/16+...)
flips per output bit, or 2 flips per bit. This is the expectation, but
reality seems to differ.
Either my code's wrong, or my logic's wrong, or reality's wrong.
Waah! Somebody help me before I spontaneously combust! :)
--
Klein bottle for rent - inquire within.
------------------------------
Date: 28 Nov 2001 00:09:37 -0800
From: dwk@auto-graphics.com (David Kenneally)
Subject: How to split file on max number of lines
Message-Id: <57a902f4.0111280009.48c1e2fc@posting.google.com>
Hello-
I'm trying to emulate the unix split function on a windows platform,
and I'm having problems. Here's what I want to do:
My script is generating a text file of variable length. The resulting
text file can be no longer than 20,000 lines. If it is longer, I need
to split it accordingly (that is, so that each piece is less than
20,000 lines). I'm kind of struggling to make that happen. I think
that incremementing a counter is the way, but its not working out.
This is what I have so far:
#This is where i count the number of lines in file
$lines = 0;
open(FILE, $to_be_counted) or die "Can't open $to_be_counted:
$!";
while (sysread FILE, $buffer, 4096) {
$lines += ($buffer =~ tr/\n//);
}
close FILE;
if ($lines > 20000) {
$count = 0;
$file_num = 0;
open(FILE2, $to_be_counted) or die "Can't open file for
split: $!";
while (defined ($buffer = <FILE2>)) {
if ($count =< 20000) {
print SOME_OUTPUT_FILEHANDLE $buffer;
$count++;
} else {
$count = 0; #set the count back to zero
$file_num++; #increment the outfile name
print SOME_NEW_OUTPUTFILENAME $buffer;
}
}
I guess my biggest problem is how to do the printing to the filename
without opening a new file handle on each pass (which I would think
would be kind of I/O intensive). In a perfect world, at the end of the
splitting I would have file1.txt, file2.txt, file3.txt, with all being
less than 20K lines.
Any ideas? Am I even on the right track? Is there some Dos system call
that I could cheat and use?
Thanks!
David Kenneally
------------------------------
Date: Wed, 28 Nov 2001 08:12:54 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: How to split file on max number of lines
Message-Id: <x7n11771o8.fsf@home.sysarch.com>
>>>>> "DK" == David Kenneally <dwk@auto-graphics.com> writes:
DK> I'm trying to emulate the unix split function on a windows platform,
DK> and I'm having problems. Here's what I want to do:
here is a pure perl version already done:
http://www.perl.com/language/ppt/src/split/index.html
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Wed, 28 Nov 2001 10:37:47 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: How to trap calls to undefined procedures at compile time
Message-Id: <sve90ucfmljqdhd6sa6u78ponse17m3let@4ax.com>
Peter Terpstra wrote:
>I think this lack of verification is a serious flaw in the language
>design. It's a pity and makes Perl less suitable for large projects.
I can see a few possible solutions.
A) One of the B::* modules (invoke with -MO=foo at the command line, if
the module is B::foo) surely must be able to connect sub calls with sub
definitions. I'm sure I've read it somewhere hen I was browsing their
docs. Try B::Lint. Ah, yes, from the POD, header "OPTIONS AND LINT
CHECKS":
undefined-subs
This option warns whenever an undefined subroutine is invoked.
This option will only catch explicitly invoked subroutines such
as "foo()" and not indirect invocations such as "&$subref()" or
"$obj->meth()". Note that some programs or modules delay
definition of subs until runtime by means of the AUTOLOAD
mechanism.
B) Coverage testing! One of the ancient computer legends is that a space
craft would have been lost because of a bug in a DO statement in the
Fortran program. I forgot the details, I will say no more. But this
surely indicates that this line had never been tested before the
spacecraft was launched!
That's the trouble with rigid, statically checked languages: people tend
to trust it too much if it only compiles. Parts of the program never get
debugged. IMO this could well be one of the reasons why Windows is so
buggy.
Coverage tests can tell you which parts of your program never got
executed in a test suite. See the perl-qa mailing list and its archives.
(<http://lists.perl.org/showlist.cgi?name=perl-qa) "qa" stands for
Quality Assurance... surely the appropriate field for this kind of
reflections?
--
Bart.
------------------------------
Date: Wed, 28 Nov 2001 10:15:46 -0000
From: "Andy Laurence" <username@this.is.a.trap.graffl.net>
Subject: Re: Internal Server Error
Message-Id: <9u2djm$5p26b$1@ID-109625.news.dfncis.de>
> > > > use CGI::Carp qw(fatalsToBrowser);
>
> > > You will benefit by reading your carp returned error messages:
>
> > The only error message I got was
>
> > Internal Server Error
> > The server encountered an internal error or misconfiguration and was
unable
>
> This leaves only three suspect lines:
>
>
> #!/usr/bin/perl
>
> use CGI qw(:standard);
> use CGI::Carp qw(fatalsToBrowser);
<snippage>
I feel such an idiot! I looked at the scripts from the console and at the
end of each line there is a ^M. This I expect is a newline character
created my the MS software I'm using to write it on. There seems to be a ^M
at the end of each line, so a simple s/^m//g; should see me through!
Thanks for your help, much appreciated.
Andy
--
PC-Based Multimedia System
http://www.andylaurence.pwp.blueyonder.co.uk/pcbmms
NB: Spamtrap - my name @yahoo.co.uk
------------------------------
Date: Wed, 28 Nov 2001 10:23:21 -0000
From: "Andy Laurence" <username@this.is.a.trap.graffl.net>
Subject: Re: Internal Server Error
Message-Id: <9u2duq$5jf9m$1@ID-109625.news.dfncis.de>
<snip>
> The error is occuring before CGI::Carp can catch it. The most likely
> problem is that there is a bad end-of-line on the shebang line,
> especialy since you are apparently transferring from Windows to Unix.
> Are you uploading these recent scripts differently from the old ones?
> The DOS newline characters may be being retained. You can edit the
> file on the server (backspace to remove any bad end of line, then enter
> a new one.) or use a local editor which will convert the file to Unix-
> compatible line endings before you upload it. The error could also
> occur if the use statement failed.
Got it in one. Cheers, it was a DOS newline character which Linux didn't
understand. I'll have to run a script to clean out the newlines before I
test the scripts. Thanks for the help.
Andy
--
PC-Based Multimedia System
http://www.andylaurence.pwp.blueyonder.co.uk/pcbmms
NB: Spamtrap - my name @yahoo.co.uk
------------------------------
Date: 28 Nov 2001 02:47:33 -0800
From: ziegler@algorilla.de (Joachim Ziegler)
Subject: is rename atomic?
Message-Id: <93aad7d0.0111280247.79602a8d@posting.google.com>
hello everybody,
i'm just asking myself wether perl's "rename"-function is atomic.
what i mean is the following:
if i update a file 'orig.txt', say i append some lines to it, i'm used
to first copy this file to a temporary file 'tmp.txt', then append the
lines to 'tmp.txt', then use the following perl-code
rename 'tmp.txt','orig.txt';
i do this in order to increase security. if the program or the
computer crashes
while writing, the original file is not lost.
but what if it crashes during 'rename'?
is 'rename' atomic in the sense that it is either carried out
completely or not all all?
greeting from germany,
joachim
------------------------------
Date: Wed, 28 Nov 2001 10:45:04 GMT
From: Chris White <chrisw_63@hotmail.com>
Subject: Re: Newbie Help...
Message-Id: <8tf90uo507eocl4kf4pdggevcsh8cc4ckc@4ax.com>
On Wed, 28 Nov 2001 09:18:53 +0930, "Wyzelli" <wyzelli@yahoo.com>
wrote:
>"HoboSong" <chrisvano@yahoo.com> wrote in message
>news:4fbb9396.0111270042.66f697e5@posting.google.com...
>> Chris White <chrisw_63@hotmail.com> wrote in message
>news:<cv160uknnk6nj48lqkil5n5gp6i10t4htd@4ax.com>...
>>
>> >
>> > #!/usr/local/bin/perl
>> > # hello.pl -- my first perl script!
>>
>> use CGI; ## </~~ Try adding "use CGI;"
>
>Why use a module when are not using any of the functions provided by that
>module?
>
>Having said that, most CGI development is greatly speeded up by using the
>CGI module, so that is good advice in a generic sense rather than for this
>particular problem.
>
>Wyzelli
I have to learn what the CGI module does first! The book I have
doesn't go into detail on the standard modules and their subroutines.
Thanks for the advice, I'll find a reference that does explain it.
Chris
------------------------------
Date: Wed, 28 Nov 2001 11:50:54 +0100
From: "Ezio PAGLIA" <ezio@toglimi.comune.grosseto.it>
Subject: Perl cgi-bin and Apache
Message-Id: <9u2egv$e0f$1@fe1.cs.interbusiness.it>
Dear perl admins and programmers,
after writing some perl programs to be used as cgi-bin from an Apache Web
Server, we were asked to protect some URLs through Apache Authorization
depending on the QUERY_STRING value. Do you know whether it is possible
either through Apache configuration or Perl ?
Our problem arises from the fact that the <Location> directive of Apache
conf file only grabs the URL, not its parameters.
Any suggestions ?
------------------------------
Date: Wed, 28 Nov 2001 10:35:05 +0000
From: Simon Oliver <simon.oliver@umist.ac.uk>
To: Jay Man <jayhaque@yahoo.com>
Subject: Re: PERL DBI ODBC... MS SQL *argh*
Message-Id: <3C04BDD9.E66AFD6A@umist.ac.uk>
Jay Man wrote:
> I am trying to write a perl script (running on solaris) thats connects
> to an MS SQL server and gets some data. I downloaded and installed the
> DBI and DBD::ODBC, since I don't have an ODBC Driver Manager I
> installed iodbc.
Try using DBD::Sybase along with FreeTDS or Sybase TDS client libraries.
Both modules link to a client TDS library such as those supplied by
Sybase and FreeTDS.
I'm told that the most recent version of DBD::Sybase doesn't work with
the current FreeTDS client libraries so use Sybase's client libraries or
an older version of DBD::Sybase (0.91).
You can get the Sybase client libraries by downloading from Sybase -
try:
http://www.sybase.com/ase_125eval
--
Simon Oliver
------------------------------
Date: 28 Nov 2001 01:09:23 -0800
From: winter7@e-mailanywhere.com (winter7)
Subject: syswrite on closed socket?
Message-Id: <fb7341b.0111280109.ab1f6bc@posting.google.com>
my server program hangs when trying to syswrite on closed socket.
client usally send message before terminate so that server can delete
client from client list. but when client terminate abnormally, server
doesn't recognize and hangs when syswrite to this client.
how do I overcome this problem?
thanks for any help..
------------------------------
Date: 28 Nov 2001 10:05:20 GMT
From: "Richard S. Smith" <rss@idiom.com>
Subject: Re: Thread Question
Message-Id: <9u2ct0$2mrf$1@news.idiom.com>
Just an FYI that I got a few replies to my post via email and the short
answer is no, there's currently no "good" way to do threading in the
production version of Perl, either on Unix or NT, but if you're on Unix the
ithreads implementation in the development version is starting to look
"interesting" and just might be worth the time to start playing around
with.
--
-----------------------------------------------------------------------
Richard S. Smith / Email: rss@idiom.com / Web: http://www.rssnet.org/
-----------------------------------------------------------------------
------------------------------
Date: Wed, 28 Nov 2001 02:58:54 -0600
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Using CGI.pm to obtain a list of params
Message-Id: <9u294h$vvi$1@nntp9.atl.mindspring.net>
"Benjamin Goldberg" <goldbb2@earthlink.net> wrote in message
news:3C047DF7.CE872B77@earthlink.net...
> [snip]
> > Name_G1
> > Address_G1
> > ...
> > Name_G12
> > Address_G12
>
> If these are the variable names, then the scheme matching Jon's
> suggestion would be:
>
> my @generations;
> for( my $i = 1; ; ++$i ) {
> defined(my $name = param("Name_G$i")) or last;
> defined(my $addr = param("Address_G$i")) or last;
> push @generations => { name => $name, addr => $addr };
> }
>
Thanks for your comments, Benjamin. I'll try your suggestions when I'm next
working on the version that uses CGI.pm. There's still the problem of having
to type in all of the variable names, which I suppose I could automate, as
well. FYI, there are about
In my particular case, however, the niceties of CGI.pm were not options, so
I converted the URL-encoded string of name-value pairs on STDIN into /T-/V
pairs as follows:
...
# FDF headers
# Code to process Tags and Values
@namevals = split(/&/,$formdat);
foreach (@namevals) {
print "<< ";
print "/T \(";
tr/+/ /;
s/=/\) \/V \(/;
# Code to move all gens down one position snipped
s/%(..)/pack("C",hex($1))/ge;
print "$_\) >>\n";
}
# FDF trailers, including /F spec
...
Please see http://segraves.tripod.com/index3.htm and submit a blank sample
form to see the FDF format.
>
> There's no need to do that ugly series of s/// things you suggest.
> And if one *were* doing something like that, it would be done as:
> s/G(\d+)$/$1 + 1/e;
> which would do all those changes with just a single substitution.
>
Well, the "ugly series of s/// things" works, but the above code doesn't. I
appreciate your suggestion, as it is evident I could code it more concisely.
I'll come back with questions (or another response) when I figure out why
your suggestion doesn't work in the above context.
Thanks again.
Bill Segraves
Auburn, AL
------------------------------
Date: Wed, 28 Nov 2001 09:32:34 GMT
From: Zoltan Kandi <zoltan.kandi@tellabs.com>
Subject: Win32::ODBC => generating a list of hashes from the query result set
Message-Id: <3C04BC44.C16C8BC5@tellabs.com>
Dear All,
I wrote a sub to accumulate all results of an SQL query in in a list of
hashes as follows:
> use strict;
> use warnings;
> use diagnostics;
> use Win32::ODBC;
> my @a=insert();
> for my $row (0..$#a) {
> print "Row $row \t";
> for my $col ( keys %{ $a[$row] } ) {
> print $col." => ".$a[$row]{$col}."\t";
> }
> print "\n";
> }
> exit;
> sub insert {
> my $dsn = "dsn";
> my $login = "uid";
> my $password = "pwd";
> my $query = "select text_id from table where text_id<11";
> my %a;
> my @adat;
> my $db = new Win32::ODBC("DSN=$dsn;UID=$login;PWD=$password;") or die "Can not connect: " . Win32::ODBC::Error();
> if( ! $db->Sql( $query ) ) {
> print "Data read from the DB\n";
> while( $db->FetchRow( \%a ) ) {
> push @adat,%a;
> foreach my $Column ( keys %a ) {
> print $Column."\t".$a{$Column}."\n"; } } }
> else {
> my $err = $db->Error;
> warn "Sql() ERROR\n";
> warn "\t\$query: $query\n";
> warn "\t\$err: $err\n": }
>
> $db->Close();
> return( @adat );
> }
and I get the following error message:
Can't use string ("text_id") as a HASH ref while "strict refs" in use at
LoH_db.pl line 7 (#1)
(F) Only hard references are allowed by "strict refs". Symbolic
references are disallowed. See perlref.
Uncaught exception from user code:
Can't use string ("text_id") as a HASH ref while "strict refs"
in use at
LoH_db.pl line 7.
The query should return
text_id 1
text_id 2
text_id 3
text_id 4
....
text_id 400
and the foreach loop after the push statement prints these results
correctly.
The reason why I wrote such a complicated sub is that I want it to be
universal, to be able to return any query results depending on the
$query, which will be ultimately passed from the caller.
Perlref has been read but I did not get any smarter.
I still think I'm referencing something wrong while fetching the results
and storing them at the list of hashes @adat. Could anyone pinpoint my
error, please?
TIA and best regards,
Zoltan Kandi, M. Sc.
Product & Application Specialist
Tellabs Netherlands BV
Perkinsbaan 17
3439 ND Nieuwegein
Tel: +31 30 600 40 75
Fax: +31 30 600 40 90
GSM: +31 651 194 291
Email: Zoltan.Kandi@tellabs.com
Internet: http://www.tellabs.com
------------------------------
Date: 28 Nov 2001 09:41:17 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: Win32::ODBC => generating a list of hashes from the query result set
Message-Id: <slrna09f6u.qsr.bernard.el-hagin@gdndev25.lido-tech>
On Wed, 28 Nov 2001 09:32:34 GMT, Zoltan Kandi <zoltan.kandi@tellabs.com>
wrote:
> Dear All,
>
>
> I wrote a sub to accumulate all results of an SQL query in in a list of
> hashes as follows:
[snipped some code]
>> if( ! $db->Sql( $query ) ) {
>> print "Data read from the DB\n";
>> while( $db->FetchRow( \%a ) ) {
>> push @adat,%a;
^^^
Shouldn't you be pushing a hashref into @adat here?
push @adat, \%a;
Cheers,
Bernard
------------------------------
Date: Wed, 28 Nov 2001 10:00:37 GMT
From: Zoltan Kandi <zoltan.kandi@tellabs.com>
Subject: Re: Win32::ODBC => generating a list of hashes from the query result set
Message-Id: <3C04C2D8.EF28631@tellabs.com>
Hi Bernard,
Bernard El-Hagin wrote:
>
[cut]
>
> >> if( ! $db->Sql( $query ) ) {
> >> print "Data read from the DB\n";
> >> while( $db->FetchRow( \%a ) ) {
> >> push @adat,%a;
> ^^^
>
> Shouldn't you be pushing a hashref into @adat here?
>
> push @adat, \%a;
>
> Cheers,
> Bernard
I know, I know... Rookie, RTFM... Now I got rid of the error message,
but
> for my $row (0..$#a) {
> print "Row $row \t";
> for my $col ( keys %{ $a[$row] } ) {
> print $col." => ".$a[$row]{$col}."\t";
> }
> print "\n";
> }
prints
Row 1<cr><lf>
...
I'm still (de)referencing something wrong, I'm afraid...
Thanks,
Zoltan
------------------------------
Date: 28 Nov 2001 10:06:49 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: Win32::ODBC => generating a list of hashes from the query result set
Message-Id: <slrna09gmp.qsr.bernard.el-hagin@gdndev25.lido-tech>
On Wed, 28 Nov 2001 10:00:37 GMT, Zoltan Kandi <zoltan.kandi@tellabs.com>
wrote:
> Hi Bernard,
>
> Bernard El-Hagin wrote:
>>
> [cut]
>>
>> >> if( ! $db->Sql( $query ) ) {
>> >> print "Data read from the DB\n";
>> >> while( $db->FetchRow( \%a ) ) {
>> >> push @adat,%a;
>> ^^^
>>
>> Shouldn't you be pushing a hashref into @adat here?
>>
>> push @adat, \%a;
>
> I know, I know... Rookie, RTFM... Now I got rid of the error message,
> but
>
>> for my $row (0..$#a) {
>> print "Row $row \t";
>> for my $col ( keys %{ $a[$row] } ) {
>> print $col." => ".$a[$row]{$col}."\t";
>> }
>> print "\n";
>> }
>
> prints
> Row 1<cr><lf>
> ...
>
>
> I'm still (de)referencing something wrong, I'm afraid...
I can't help you with that since I don't know how %a is filled.
I see it used only in the FetchRow method so that must be the place,
but I've never used DBI and don't know anything about it. Hold tight,
though, I'm sure you'll get more help in a little while from someone
else.
Cheers,
Bernard
------------------------------
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 2225
***************************************