[12960] in Perl-Users-Digest
Perl-Users Digest, Issue: 370 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 4 17:17:24 1999
Date: Wed, 4 Aug 1999 14:10:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 4 Aug 1999 Volume: 9 Number: 370
Today's topics:
reading in multiple unknown files and writing to it quyluu@my-deja.com
Re: Repetition in RE substitutions (Ilya Zakharevich)
Re: server-side databases (John Casey)
Re: towards uploading binary files... irf@netexecutive.com
Re: truncating decimals (Larry Rosler)
Re: Useless error when {} unbalanced <aqumsieh@matrox.com>
while loop teminates too early <acollado@uiuc.edu>
Re: while loop teminates too early (K. Krueger)
Re: while loop teminates too early (Andrew Johnson)
Re: while loop teminates too early <acollado@uiuc.edu>
Re: Why is it.... feinster@my-deja.com
Re: Why is it.... (John Casey)
Re: Why is it.... (John Casey)
Re: Why is it.... (K. Krueger)
Re: Why is it.... (Greg Bacon)
Re: Why is it.... (Greg Bacon)
Re: Why is it.... <uri@sysarch.com>
Re: Why is it.... <laurens@bsquare.com>
Re: Why is it.... <sariq@texas.net>
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 04 Aug 1999 19:33:54 GMT
From: quyluu@my-deja.com
Subject: reading in multiple unknown files and writing to it
Message-Id: <7oa4j1$sm1$1@nnrp1.deja.com>
Hi Im trying to open all *.txt files in a directory and append to
the beginning of the file. I know my appending part is not correct,
but I cannot seem to be able to open *.txt files in a dir, for writing,
just raeding.
Here is one of the things i've tried:
while(open(FILE,<*.txt>)) {
print ("Opening works!\n");
seek FILE,0,0; #this statement doesnt seem tow ork
write(FILE,"IT WORKS!"); #this doesn't cuz i can't open it for
#writing
close(FILE);
}
I've tried...doing open(FILE,">*.txt") doesn't work
Any help is GREATLY Appreciated!
Kevin
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: 4 Aug 1999 19:54:30 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Repetition in RE substitutions
Message-Id: <7oa5pm$48v$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Uri Guttman
<uri@sysarch.com>],
who wrote in article <x73dxzk1i1.fsf@home.sysarch.com>:
> so yours would become:
>
> s/(?<=\d)-(?=\d)//g ;
>
> we assert there is a digit on either side of the - which we replace with
> the null string.
And with the proposed \g< \g> it would become
s/ \d \g< - \g> \d //gx
("delimit what goes into $&").
Ilya
------------------------------
Date: Wed, 04 Aug 1999 19:57:50 GMT
From: jcasey@workingventures.ca (John Casey)
Subject: Re: server-side databases
Message-Id: <37a89a0c.109396844@wv-proxy>
I really can't educate you too much on what to do as I am a newbie
myself, but this is one of the first perl db files I wrote so it is
fairly simple. USE WIN32::ODBC, IT IS PAINLESS. The example is very
simple, but you will get the idea.
odbc connection name: testodbc
table name: test1
fields: name
address
phone
=======================================================
#!/perl5/bin/perl.exe
use Win32::ODBC;
my($db) = new Win32::ODBC('testodbc');
$db->Sql("SELECT * from test1");
print "Content-Type: text/html\n\n";
print "<HTML><BODY>\n";
print "<TABLE border=1>\n";
while ($db->FetchRow()) {
my(%data) = $db->DataHash();
print "<TD>$data{'Name'}\n";
print "<TD>$data{'Address'}\n";
print "<TD>$data{'Phone'}<TR>\n";
}
print "</TABLE>\n";
print "</BODY></HTML>\n";
$db->Close();
=======================================================
On Tue, 03 Aug 1999 21:46:45 +0100, Peter <pjw7@ukc.ac.uk> wrote:
>If I want to build a server-side database for interaction with web pages
>what would be the best option?
>
>Construct the database in Perl?
>
>or
>
>Construct the database in another language (I'm more familiar with Java
>) and use Perl as a front end when making queries?
>
>Any pointers to web sites that would help me with this subject would be
>greatly appreciated.
>
>
>Thanks
>
>
>Peter
------------------------------
Date: Wed, 04 Aug 1999 19:33:07 GMT
From: irf@netexecutive.com
Subject: Re: towards uploading binary files...
Message-Id: <7oa4hj$sln$1@nnrp1.deja.com>
>> hi i am relatively new to perl & :
>You are new to colons?
read it like someone cool be sayin it (urrk)
%% read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
%% $dat=$buffer;
>THAT IS WRONG!
eh? no it's not. i'm using it now, and thanks to a nudge from sexy larry
(what a great pic on your homepage, man) :) it works. it's better to
check bytes,and this whole thing is probably ultra-insecure, but it
isn't WRONG.
>What if you don't read enough? Why don't you use 'use CGI;'?
because i'm a fussy little satan, and i want to know how to parse it
myself. don't ask why :)
>Are you sure your substitutions on $dat are valid? Which spec do you
use
>that tells you that those substitutions give you a valid gif image?
the subs just delete the multipart form header, and this 'closing
line'(?) that has 29 -'s and machine generated numbers and then 2 more
-'s, which i assume is the form header closing.
was using gnosis specs that the rest was file data, and if you print it
out, it is indeed those fun characters. but larry helped cos
he said binary files MAY contain \n characters, and my subs were
deleting all of them - so i rewrote that part.
anyway, here's the code that works, if anyone cares for it. i'd
appreciate it if someone could tell me if my bytes-checking is correct
(see the $bytesread variable)
--------------------------------------------------
print "Content-type: image/gif\n\n";
binmode(STDIN);
$bytesRead=read(STDIN, $dat, $ENV{'CONTENT_LENGTH'});
if ($bytesRead==$ENV{'CONTENT_LENGTH'}){
$dat=~s/.*\n.*\n.*\n//;
$dat=~s/\-+\d+\-+//;
$dat=~s/\n//;
$dat=~s/\r//;
binmode (STDOUT);
print "$dat";
}
--------------------------------------------------
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Wed, 4 Aug 1999 12:49:27 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: truncating decimals
Message-Id: <MPG.1212392631bfbcfb989dc6@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <7oa292$qpr$1@nnrp1.deja.com> on Wed, 04 Aug 1999 18:54:31
GMT, Stone Cold <paulm@dirigo.com> says...
...
> foreach $x (@$rows) {
> print "<tr><td valign=middle align=center width=15%>$pmonth ";
>
> $pmonth is the result of an equation within my script. It will output
> the revenue dollars per month. My question is "where do I put the printf
> (%.2f, etc) function if my "print" is in a foreach loop.
foreach $x (@$rows) {
printf
"<tr><td valign=middle align=center width=15%%>%.2f ",
$pmonth;
But that doesn't make much sense unless $pmonth is a function of $x that
you have omitted.
Note the doubled '%%' -- I though't I would save you a Gotcha!
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 4 Aug 1999 13:33:50 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Useless error when {} unbalanced
Message-Id: <x3yr9ljcuwx.fsf@tigre.matrox.com>
fmgst+@pitt.edu (Filip M. Gieszczykiewicz) writes:
> 2) vi's "%" matching of {}() for the brute-force cases...
> not too fun with >1500 lines....
Ahh .. this shows how convenient Emacs's perl-mode is!
Thanks Ilya.
Syntax coloring, along with auto-indentation, will almost surely solve
your problem in seconds. Ofcourse some things might throw it off like
having a '}' in a comment somewhere.
But that's a different story for a different time ..
HTH,
Ala
------------------------------
Date: Wed, 04 Aug 1999 15:00:00 -0500
From: Andy Collado <acollado@uiuc.edu>
Subject: while loop teminates too early
Message-Id: <37A89BC0.E073F6EC@uiuc.edu>
I have a while loop that should verify that a user is valid, but it will
only validate whoever is the first user in the user file.
Here's the block of code that I'm using:
open (USERS, "C:/www/users");
while($line=<USERS>) {
if ($line=~/^$user/) {
✓
}
else {
&goaway;
}
exit;
}
If I play with the user file and change who is the first one in the
file, then only they become a valid user.
Here's the user file:
kmullen:$apr1$qY2.....$2r1EKQcBLXulxUaFRICg8.
acollado:$apr1$Ll4.....$iwC53pKUaJnh/Gro8Z2rH/
hhahn:$apr1$Z3......$vSp1FZHmLrutx2c2vauU7.
yihsinlo:$apr1$rq4.....$XUQ3.laWYAVNGJiUGHLYV/
spong:$apr1$tr4.....$dC2QmO12gcxEqvfplMDWh1
dblock:$apr1$Rs4.....$BDxm9seUD.UdoUnOByEse.
yomama:$apr1$W/3.....$SukGsPqBUYkFyqSClAPC60
------------------------------
Date: 4 Aug 1999 13:10:18 -0700
From: kirbyk@best.com (K. Krueger)
Subject: Re: while loop teminates too early
Message-Id: <7oa6na$q59$1@shell2.ba.best.com>
In article <37A89BC0.E073F6EC@uiuc.edu>,
Andy Collado <acollado@uiuc.edu> wrote:
>I have a while loop that should verify that a user is valid, but it will
>only validate whoever is the first user in the user file.
>Here's the block of code that I'm using:
>
>open (USERS, "C:/www/users");
>while($line=<USERS>) {
> if ($line=~/^$user/) {
> ✓
> }
> else {
> &goaway;
> }
> exit;
^^^^^^
>}
>
>
Well, of course. Look at where your exit line is. It reads the first line,
does the if/then/else stuff, and then exits. You really want that one level
out, outside of the while loop, I suspect.
--
Kirby Krueger O- kirbyk@best.com
<*> Lips that taste of tears, they say, are the best for kissing - D. Parker
------------------------------
Date: Wed, 04 Aug 1999 20:35:58 GMT
From: andrew-johnson@home.com (Andrew Johnson)
Subject: Re: while loop teminates too early
Message-Id: <Ou1q3.4167$K%6.119084@news1.rdc2.on.home.com>
In article <37A89BC0.E073F6EC@uiuc.edu>,
Andy Collado <acollado@uiuc.edu> wrote:
! I have a while loop that should verify that a user is valid, but it will
! only validate whoever is the first user in the user file.
! Here's the block of code that I'm using:
!
! open (USERS, "C:/www/users");
always test your open() calls for success:
open(USERS, 'C:/www/users') || die "Can't open file: $!";
! while($line=<USERS>) {
! if ($line=~/^$user/) {
you might consider doing:
while(<USERS>) {
if (/^$user/) {
! ✓
! }
! else {
! &goaway;
! }
! exit;
! }
hmm ... and you say this only validates against the first
user in the file ... almost like your program was reading
in a line, checking the user, and then it simply exits at
the bottom of the loop? I wonder why it would that?
regards
andrew
--
Reality is that which, when you stop believing in
it, doesn't go away.
-- Philip K. Dick
------------------------------
Date: Wed, 04 Aug 1999 16:04:48 -0500
From: Andy Collado <acollado@uiuc.edu>
Subject: Re: while loop teminates too early
Message-Id: <37A8AAF0.93A8568E@uiuc.edu>
Andy Collado wrote:
> I have a while loop that should verify that a user is valid, but it will
> only validate whoever is the first user in the user file.
> Here's the block of code that I'm using:
>
> open (USERS, "C:/www/users");
> while($line=<USERS>) {
> if ($line=~/^$user/) {
> ✓
> }
> else { -------!
> &goaway; -------!
> } --------!
> exit;
> }
>
>
Evidently, the while loop does not like the else statement inside it. Once
I took that out, it worked fine. All i had to do was invoke the sub &goaway
outside the while loop and all went well.
------------------------------
Date: Wed, 04 Aug 1999 19:34:10 GMT
From: feinster@my-deja.com
Subject: Re: Why is it....
Message-Id: <7oa4jh$sm7$1@nnrp1.deja.com>
> I think he's aware of that. What's keeping those people from checking
out
> the group via Deja.com or checking out the FAQ before they post
questions
> that have already been asked many times before?
>
gee... it just maybe _possibly_ might be easier to ASK a question in a
newsgroup rather than spend hours searching through the docs... ya'
think?
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Wed, 04 Aug 1999 19:42:33 GMT
From: jcasey@workingventures.ca (John Casey)
Subject: Re: Why is it....
Message-Id: <37a896d1.108569364@wv-proxy>
I have heard that jerking off multiple times a day increases your
capacity for learning Perl and makes you a boastful ass hole. Yup,
thats got to be it.
On Wed, 04 Aug 1999 09:28:40 -0400, Chris Goodwin
<archer7@mindspring.com> wrote:
>why is it that I, who have only been hacking Perl for ~3 days, can read
>through the documentation and the previous newsgroup postings (7000+ of them
>on my server) and write up a 122-line program that does what I want it to do
>(which is turn my text into my HTML -- not *entirely* finished yet, but the
>rest is details -- I've gotten over my hurdles), all *without* having to ask
>anyone for help, while other people around here, who apparently have been
>hacking Perl for longer than I, have to come in and ask the same questions
>over and over?
>
>--
>Making the world safe for anocracy! http://www.mindspring.com/~archer7
>L. Neil Smith Supporter http://members.xoom.com/smith4prez
>Sign up for E-gold: http://www.mindspring.com/~archer7/e-gold.html
------------------------------
Date: Wed, 04 Aug 1999 19:48:35 GMT
From: jcasey@workingventures.ca (John Casey)
Subject: Re: Why is it....
Message-Id: <37a898b8.109056685@wv-proxy>
When you figure out how to hook a database up to a web page with full
view/modify/add/delete capability then we will be impressed...we will
still think you are a boastful ass hole though.
On Wed, 04 Aug 1999 19:42:33 GMT, jcasey@workingventures.ca (John
Casey) wrote:
>I have heard that jerking off multiple times a day increases your
>capacity for learning Perl and makes you a boastful ass hole. Yup,
>thats got to be it.
>
>On Wed, 04 Aug 1999 09:28:40 -0400, Chris Goodwin
><archer7@mindspring.com> wrote:
>
>>why is it that I, who have only been hacking Perl for ~3 days, can read
>>through the documentation and the previous newsgroup postings (7000+ of them
>>on my server) and write up a 122-line program that does what I want it to do
>>(which is turn my text into my HTML -- not *entirely* finished yet, but the
>>rest is details -- I've gotten over my hurdles), all *without* having to ask
>>anyone for help, while other people around here, who apparently have been
>>hacking Perl for longer than I, have to come in and ask the same questions
>>over and over?
>>
>>--
>>Making the world safe for anocracy! http://www.mindspring.com/~archer7
>>L. Neil Smith Supporter http://members.xoom.com/smith4prez
>>Sign up for E-gold: http://www.mindspring.com/~archer7/e-gold.html
>
------------------------------
Date: 4 Aug 1999 13:03:26 -0700
From: kirbyk@best.com (K. Krueger)
Subject: Re: Why is it....
Message-Id: <7oa6ae$onu$1@shell2.ba.best.com>
In article <7oa4jh$sm7$1@nnrp1.deja.com>, <feinster@my-deja.com> wrote:
>
>
>> I think he's aware of that. What's keeping those people from checking
>out
>> the group via Deja.com or checking out the FAQ before they post
>questions
>> that have already been asked many times before?
>>
>gee... it just maybe _possibly_ might be easier to ASK a question in a
>newsgroup rather than spend hours searching through the docs... ya'
>think?
>
>
Well, yes. That's almost assuredly why people do it.
However, answering the same questions over and over again is a big waste
of time for the volunteers in this newsgroup that are willing to help
out beginners.
The current roughshod approach basically embraces the policy that we can't
really stop people from asking FAQs once, but we can certainly stop them
from doing it twice. And it probably works - those that aren't completely
scared off do figure out that we expect people to read the basic
documentation before getting a civil answer.
Unfortunately, the nature of the group is to attract a lot of first-time
posters. While it used to be the Usenet standard that people would read
a group for a little while before posting a question (ah, the glorious
past!) we have little hope of getting those days back. There's nothing
I can think of to address the problem of first-time posters posting
FAQs that isn't radical.
However, if we do want radical, there are options. We could make the
group moderated, and only allow posting by people who have validated
themselves through a cgi that very explicitly states the ground rules
and how to find the FAQs. This additional hurdle would be a burden for
a lot of first time posters - but as a group, they've shown themselves
to be a burden on the regulars, so perhaps we shouldn't worry about
this so much. Other similar radical ideas could be implemented.
I have no real interest in championing such a cause. I'll let someone
who cares more about keeping this newsgroup useful than I do such a
thing, if they want. I'll certainly support it, however - it'd be
nice to be able to read this without 80% of the posts being FAQs or
pointers to FAQs.
--
Kirby Krueger O- kirbyk@best.com
<*> Lips that taste of tears, they say, are the best for kissing - D. Parker
------------------------------
Date: 4 Aug 1999 20:08:57 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: Why is it....
Message-Id: <7oa6kp$njb$1@info2.uah.edu>
In article <MPG.12122761cffe50ed989dc1@nntp.hpl.hp.com>,
lr@hpl.hp.com (Larry Rosler) writes:
: Some are born programmers, some achieve programming, and some have
: programming thrust upon 'em.
Some are born physicians, some achieve medicine, and some have medicine
thrust upon 'em.
How ridiculous does that sound?
: Too many of the latter these days, I trow! But there is lots of hope
: for the middle class, especially with modern tools and with this kind
: of newsgroup support.
Perhaps we can improve the state of health care by providing newsgroup
support and more modern tools too.
Get serious.
Greg
--
Never shy away from starting up an extra process if all it takes is a
configuration line in a web server. People might think your site is fast!
-- Abigail in <slrn7pe937.oqh.abigail@alexandra.delanet.com>
------------------------------
Date: 4 Aug 1999 20:13:49 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: Why is it....
Message-Id: <7oa6tt$njb$2@info2.uah.edu>
In article <37a896d1.108569364@wv-proxy>,
jcasey@workingventures.ca (John Casey) writes:
: I have heard that jerking off multiple times a day increases your
: capacity for learning Perl and makes you a boastful ass hole. Yup,
: thats got to be it.
Do I detect a hint of jealousy? :-) Figure out how to quote properly
and we'll be impressed.
Greg
--
When the speaker and he to whom he is speaks do not understand, that is
metaphysics.
-- Voltaire
------------------------------
Date: 04 Aug 1999 16:20:31 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Why is it....
Message-Id: <x7oggni9gw.fsf@home.sysarch.com>
>>>>> "DC" == David Cassell <cassell@mail.cor.epa.gov> writes:
DC> BTW, why is it acceptable to tell people that they have no
DC> athletic ability, no musical ability, etc., but you
DC> are a creep if you try to tell someone they have no gift
DC> for programming?
because ANYONE can write a hello world program even if they can't thorw a
ball straight or hold a tune. beginning programming is so easy but after
those first few steps, it is as hard as we know it to be. yet there are
naturals (who would still benefit from structured training like any
prodigy would). the other thing is that we are amazed at a musical or
athletic prodigy where you could possibly excell with out much
experience. much of my programming knowledge and skill is my 25 years of
experience. you can't teach that. but others don't get it and don't want
my knowledge. sometimes a buch of kiddies woking like monkeys for 20
hours a day is what they want and they deserve the problems they
create. you can't tell them they are wrong to their faces since they are
the company. i feel like a prophet of doom many places when i tell them
they will fall on their faces unless they do some long term
planning. but will a startup ever listen?
:-(
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.
------------------------------
Date: Wed, 4 Aug 1999 13:08:57 -0700
From: "Lauren Smith" <laurens@bsquare.com>
Subject: Re: Why is it....
Message-Id: <7oa6l3$kiv$1@brokaw.wa.com>
feinster@my-deja.com wrote in message <7oa4jh$sm7$1@nnrp1.deja.com>...
>
>gee... it just maybe _possibly_ might be easier to ASK a question in a
>newsgroup rather than spend hours searching through the docs... ya'
>think?
>
Let's see...
On the one hand, I could take a little bit of time (I've never had to spend
'hours' in the FAQ to find an answer to a question, maybe that's just my
experience) and find the right answer and maybe learn a few things.
Or I could post a question that someone may or may not respond to. And if I
do get an answer, I can't be sure that it is a correct one. Most likely I
would get a lot of flamage and, if lucky, pointed to the FAQ that I should
have looked at in the first place.
Yep, asking in the newsgroup is much better (and faster) than checking to
see if my question has already been answered in the FAQ.
Lauren
------------------------------
Date: Wed, 04 Aug 1999 15:27:03 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: Why is it....
Message-Id: <37A8A217.2594CB30@texas.net>
feinster@my-deja.com wrote:
>
> gee... it just maybe _possibly_ might be easier to ASK a question in a
> newsgroup rather than spend hours searching through the docs... ya'
> think?
*sigh*
Kids these days. It's hopeless.
- Tom
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 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.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 370
*************************************