[13398] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 808 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 15 16:17:24 1999

Date: Wed, 15 Sep 1999 13:05:15 -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, 15 Sep 1999     Volume: 9 Number: 808

Today's topics:
    Re: Abigail, Abigail, wherefore art thou, Abigail? a.k. (Abigail)
        Abigail, Abigail, wherefore art thou, Abigail? a.k.a. R <camerond@mail.uca.edu>
        Can Perl talk to Javascript?? (wolflake)
    Re: Can Perl talk to Javascript?? (Abigail)
    Re: CGI /PL permissions (Kragen Sitaker)
    Re: CGI cannot open relative path (Kragen Sitaker)
        CGI programs that output chinese (Stearns25)
    Re: CGI programs that output chinese (Kragen Sitaker)
    Re: command to update the mainloop during longrunning s <lusol@Pandora.CC.Lehigh.EDU>
    Re: Design Advice needed on Sending Data to Client (Kragen Sitaker)
    Re: Design Advice needed on Sending Data to Client (Kragen Sitaker)
    Re: Error in "Learning Perl, 2nd Edition" or Error in P <uri@sysarch.com>
    Re: Help with compiling a list (Kragen Sitaker)
    Re: Hot, Fun S.F Startup Seeks a Gaggle of Perl People (Randal L. Schwartz)
    Re: How do I delete apostraphe from a string? (Kragen Sitaker)
    Re: How to match with m/$variable/ ?? (Kragen Sitaker)
    Re: How to validate a URL? <tech@tburg.net>
    Re: perl to shell <makkulka@cisco.com>
    Re: Sendmail: Address family not supported by protocol  (Abigail)
        The DB_File locking method is flawed <dharris@drh.net>
    Re: trimming spaces from a string (Kragen Sitaker)
    Re: trimming spaces from a string <aqumsieh@matrox.com>
    Re: trimming spaces from a string <aqumsieh@matrox.com>
    Re: trimming spaces from a string (Larry Rosler)
    Re: trimming spaces from a string (Larry Rosler)
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 15 Sep 1999 15:02:16 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Abigail, Abigail, wherefore art thou, Abigail? a.k.a. Re: Error in  "Learning Perl, 2nd Edition"
Message-Id: <slrn7tvuv8.hj3.abigail@alexandra.delanet.com>

Cameron Dorey (camerond@mail.uca.edu) wrote on MMCCVI September MCMXCIII
in <URL:news:37DFF730.E99D7B6@mail.uca.edu>:
'' Brian Clark wrote:
'' > 
'' > For some reason, I never see Abigail's posts. I have read many
'' > messages/replies with Abigail's quoted text, but I never get Abigail's
'' > actual message.
'' 
'' The same thing happens to me, although I used to see Abigail's posts all
'' the time (until April, anyway, don't ask me to figure out the September
'' MCMXCIII date). Thought it was something uniquely wrong with my feed,
'' like I had been killfiled from the sender end somehow. I think that they
'' were cut off when Abby's address changed to delanet.com, maybe your/my
'' news source filters out messages from that source? Anyway, it's a real
'' annoyance for me, if only because I don't get my minimum daily
'' requirement of punctuation any more.

I've heard this problem before. I have the same problem with posts of
certain other people. The only reason I can think of is "news farms".
My ISP doesn't have the 2 braincells to run their own newsfeed, and
hence had to outsource it. It seems there is some competition going
on, and news farms seem to drop posts coming from certain streams,
for whatever reason they can come up with.



Abigail
-- 
sub camel (^#87=i@J&&&#]u'^^s]#'#={123{#}7890t[0.9]9@+*`"'***}A&&&}n2o}00}t324i;
h[{e **###{r{+P={**{e^^^#'#i@{r'^=^{l+{#}H***i[0.9]&@a5`"':&^;&^,*&^$43##@@####;
c}^^^&&&k}&&&}#=e*****[]}'r####'`=437*{#};::'1[0.9]2@43`"'*#==[[.{{],,,1278@#@);
print+((($llama=prototype'camel')=~y|+{#}$=^*&[0-9]i@:;`"',.| |d)&&$llama."\n");


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


------------------------------

Date: Wed, 15 Sep 1999 14:44:48 -0500
From: Cameron Dorey <camerond@mail.uca.edu>
Subject: Abigail, Abigail, wherefore art thou, Abigail? a.k.a. Re: Error in  "Learning Perl, 2nd Edition"
Message-Id: <37DFF730.E99D7B6@mail.uca.edu>

Brian Clark wrote:
> 
> > >Abigail wrote:
> > [snip]
> 
> For some reason, I never see Abigail's posts. I have read many
> messages/replies with Abigail's quoted text, but I never get Abigail's
> actual message.

The same thing happens to me, although I used to see Abigail's posts all
the time (until April, anyway, don't ask me to figure out the September
MCMXCIII date). Thought it was something uniquely wrong with my feed,
like I had been killfiled from the sender end somehow. I think that they
were cut off when Abby's address changed to delanet.com, maybe your/my
news source filters out messages from that source? Anyway, it's a real
annoyance for me, if only because I don't get my minimum daily
requirement of punctuation any more.

Anybody know what is going on, and who I should complain to?

Cameron

-- 
Cameron Dorey
Associate Professor of Chemistry
University of Central Arkansas
Phone: 501-450-5938
camerond@mail.uca.edu


------------------------------

Date: Wed, 15 Sep 1999 18:50:22 GMT
From: wolflake@xxorn.net (wolflake)
Subject: Can Perl talk to Javascript??
Message-Id: <37e9e631.18157097@news.supernews.com>

Hi,

One way I thought of is to pass info through a cookie.  Javascript
could set the cookie call perl which could read and change the cookie
and reload the form where javascript would read the cookie with the
info perl set.

My question is how could perl talk to javascript if cookies were
disabled?

Any ideas?

Thanks is advance.

-Rick

If you want to email me take the xx out of my address
wolflake@xxorn.net 


------------------------------

Date: 15 Sep 1999 14:33:04 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Can Perl talk to Javascript??
Message-Id: <slrn7tvt8g.hj3.abigail@alexandra.delanet.com>

wolflake (wolflake@xxorn.net) wrote on MMCCVI September MCMXCIII in
<URL:news:37e9e631.18157097@news.supernews.com>:
## 
## My question is how could perl talk to javascript if cookies were
## disabled?

Perl has many ways to communicate to different programs, none of which
are specific to the other program. You might want to read 'man perlipc'.

You would have to pick a way of communicating that JavaScript understands.

Of course, if JavaScript program is being run inside a wowser, you need to
figure out how to communicate with the wowser, not to JavaScript directly.



Abigail
-- 
perl -wle '$, = " "; print grep {(1 x $_) !~ /^(11+)\1+$/} 2 .. shift'


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


------------------------------

Date: Wed, 15 Sep 1999 19:22:07 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: CGI /PL permissions
Message-Id: <zlSD3.13264$N77.957900@typ11.nn.bcandid.com>

In article <aOGD3.37558$aX6.58909@news20.bellglobal.com>,
Greg White <whiteg@sympatico.ca> wrote:
>-=-=-=-=-=-
>
>The first digit equates to the file owner privledges. The second digit
>is for the group and the third is for everyone. Thus:
>
>owner  group  others
>xwr    xwr    xwr        (execute, write, read)
>111    101    001        (binary)
>7      5      1          (decimal)

This is backwards.  The bit order is rwx; read-only is 4, not 1.

You can think of it as translating three groups of three bits
individually to decimal or octal, or you can think of it as translating
the whole number to octal.

(Jeopardist.)
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Tue Sep 14 1999
55 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


------------------------------

Date: Wed, 15 Sep 1999 19:09:25 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: CGI cannot open relative path
Message-Id: <F9SD3.13254$N77.956655@typ11.nn.bcandid.com>

In article <MPG.124989a8c2b99be0989f6b@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
>But slower.  Depending on the application, this may be a performance 
>issue.

I thought he said this was a CGI script.  If he was concerned about
performance, he'd be using FastCGI.

>It is far faster to do one chdir() and then make relative accesses on 
>the output of readdir than to make a bunch of absolute accesses, where 
>the directory path has to be traversed for each one.

Right, of course.
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Tue Sep 14 1999
55 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


------------------------------

Date: 15 Sep 1999 19:20:53 GMT
From: stearns25@aol.com (Stearns25)
Subject: CGI programs that output chinese
Message-Id: <19990915152053.01481.00001091@ng-cg1.aol.com>

I want to use Perl to write a CGI program to generate a few Chinese web pages
on a Linux server.

Is there a version of Perl or a Perl module that supports the output (using
print, printf) of Chinese on Linux?

TIA.

-al
 


------------------------------

Date: Wed, 15 Sep 1999 19:46:43 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: CGI programs that output chinese
Message-Id: <DISD3.13310$N77.960281@typ11.nn.bcandid.com>

In article <19990915152053.01481.00001091@ng-cg1.aol.com>,
Stearns25 <stearns25@aol.com> wrote:
>I want to use Perl to write a CGI program to generate a few Chinese web pages
>on a Linux server.
>
>Is there a version of Perl or a Perl module that supports the output (using
>print, printf) of Chinese on Linux?

Have you tried putting Chinese strings in quotes and trying to print them?  :)

Are you using a straightforward (e.g. EUC, Unicode UTF-8) encoding for
your Chinese characters, or do you have to emit escape sequences to
enter and leave Chinese mode (like, I believe, Shift-JIS)?
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Tue Sep 14 1999
55 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


------------------------------

Date: 15 Sep 1999 19:05:25 GMT
From: "Stephen O. Lidie" <lusol@Pandora.CC.Lehigh.EDU>
Subject: Re: command to update the mainloop during longrunning subs?
Message-Id: <7roqll$14ai@fidoii.cc.Lehigh.EDU>

[L] Vicious! <baal@c2i.net> wrote:
> I was wondering if there is a command which updates the Mainloop (or updates
> the topwindow) when using the Tk module. I need it to give some feedback of
> the progress of a longrunning sub. I've seen through the faq, but didn't
> find anything. After checking with my books I found the command
> tkwait("visibility", $toplevelwindow), but I recon the Win32 version of perl
> (Activeperl) does not support it, since it didn't work, neither did I find

I suspect if you use a book on Perl/Tk instead of Tcl/Tk you might have
better luck.

Minimally:

	$mw->idletasks; # (or $mw->update)

> it in the faqs. I run Win98 and Activeperl.

> Thnx!



-- 
-- 
Stephen.O.Lidie@Lehigh.EDU
Lehigh University Computing Center, USA


------------------------------

Date: Wed, 15 Sep 1999 19:34:10 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Design Advice needed on Sending Data to Client
Message-Id: <SwSD3.13282$N77.958772@typ11.nn.bcandid.com>

In article <7rmkld$9hp$1@nnrp1.deja.com>,  <caitlynhay@my-deja.com> wrote:
>The reason I chose http is bec. that's the only way I know besides
>ftp.  I can't use ftp because the object to transfer is a dynamic
>array, and it causes too many problems to save the dynamic array to a
>temp file.

You could write your own ftp server.

>So far, I have written a server script which writes the array to the
>response object line by line via a html/text stream.  I notice the
>problem with this method is that the client cannot proceed until the
>response object is fully constructed at the client side.

Possibly your output is buffered, either by your language facilities or
by your web server.

>  This can
>become a problem when the array size is large.  I'm not sure if this is
>a problem with my test client program (VC++ and VB) though.

If it's a buffering problem, writing an enormous array (>64K should do
it for sure; probably >1K would be fine) would cause something to be
written out from the buffer.

>What protocols are all those stock programs using to get historical
>data from the quote servers?  That's basically what I have to do.  So,
>is http the choice or not?

Probably HTTP.

>In article <FDbD3.8333$N77.652041@typ11.nn.bcandid.com>,
>  pacman@defiant.cqc.com (Alan Curry) wrote:

Please don't quote the entire article in your followup.  If you're
going to quote it, quote only relevant parts, and put them right above
where you respond to them.
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Tue Sep 14 1999
55 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


------------------------------

Date: Wed, 15 Sep 1999 19:36:46 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Design Advice needed on Sending Data to Client
Message-Id: <izSD3.13293$N77.959394@typ11.nn.bcandid.com>

In article <7rmgmk$6k6$1@nnrp1.deja.com>,  <caitlynhay@my-deja.com> wrote:
>My impression is that a response is consists of a response header, and
>a response body.
>
>For e.g, when a browser request for a html page from a server.  The
>server returns the reponse header which consists of the content type,
>content length, etc.  Whereas, the response body contains the html of
>the requested page.  Or, am I totaly off track?

You're right.  (Well, to be pedantic, some responses have no bodies,
and some headers don't include content-length, and all of this is only
valid if the two are talking HTTP.)

>Is there any way to view the response header in a web browser?

That's up to the Web browser.  It's not a Perl question.

I thought you were telnetting to the Web server and typing HTTP
requests at it.

lynx lets you view response headers by hitting ']'.
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Tue Sep 14 1999
55 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


------------------------------

Date: 15 Sep 1999 15:34:20 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Error in "Learning Perl, 2nd Edition" or Error in Perl port specific to Windows or ?
Message-Id: <x7n1uoj7er.fsf@home.sysarch.com>

>>>>> "RLS" == Randal L Schwartz <merlyn@stonehenge.com> writes:

>>>>> "Randal" == Randal L Schwartz <merlyn@stonehenge.com> writes:
>>>>> "Uri" == Uri Guttman <uri@sysarch.com> writes:
  Uri> END {push @l, sprint "$w was seen $c times!\n" while ($w, $c) = each %c;
  Uri> print sort @l}

  RLS> push @l, "$w was seen $c times!\n" while ($w, $c) = each %c;

that is what i meant to do (and have done). it was a shoddy cut and paste
job leaving the sprint there. my goal was trying to show the sort
on the output strings and how you can use each and sort together.

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, 15 Sep 1999 19:29:00 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Help with compiling a list
Message-Id: <0sSD3.13268$N77.958140@typ11.nn.bcandid.com>

In article <7rlp5d$mah$1@nnrp1.deja.com>,  <jsilve1@my-deja.com> wrote:
>  Actually, my question is probably more algorithm-oriented rather than
>perl-specific, but since i'm writing the script in perl...enuff preface.
>
>I want to take a database of names and email addresses and extract
>mailing lists based on user input (this is a cgi script for a website).

Is this a relational database or is this a text file?

>the data is compiled thus:
>group	firstn	lastn	email
>=============================
>PI	John	Smith	js@blah.edu
>STAFF	Jane	Doe	jdoe@fun.place.edu
>PI	Betty	Tooth	Btooth@school.edu
>
>etc...
>Now, some of these people are in more than one "group", e.g. different
>committees, that I want to be able to extract based on what group a user
>chooses to have email listed for.

The relationally correct way to do it is with two tables: one mapping
email addresses (or unique keys, if you have multiple people with the
same email address) to first and last names, and a second table mapping
addresses (or keys) to groups.

The Unix/XML/text way is just as you say:

>I tried something like:
>STAFF,COMMITTEE_A	Fred	Beagle	fbeagle@usa.school.edu
>
>but I am having trouble getting the script to recognize this first field
>as containing two separate groups.

split /,/, $firstfield
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Tue Sep 14 1999
55 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


------------------------------

Date: 15 Sep 1999 12:53:19 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Hot, Fun S.F Startup Seeks a Gaggle of Perl People
Message-Id: <m1aeqo9ck0.fsf@halfdome.holdit.com>

>>>>> "harad" == harad  <harad@my-deja.com> writes:

harad> 2)  Web Programmer (3 openings)

Yeah, can you program the web so that it stops that annoying
"flashing 12" all night?  Sheesh!

harad> Sent via Deja.com http://www.deja.com/
harad> Share what you know. Learn what you don't.
       B**ls**t when you're not sure.  Posture when you don't care.

:-)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


------------------------------

Date: Wed, 15 Sep 1999 19:43:09 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: How do I delete apostraphe from a string?
Message-Id: <hFSD3.13304$N77.953588@typ11.nn.bcandid.com>

In article <x3yyaeih9u1.fsf@tigre.matrox.com>,
Ala Qumsieh  <aqumsieh@matrox.com> wrote:
>Matt Duggan <matt@insnet.net> writes:
>> Has anyone got an idea of what the regular expression
>> to delete an apostraphe from a string would be?
>
>It is very similar to the regular expression to delete the letter
>'a'.
>
>	tr/'//d;

This is not a regular expression, and it will delete *every* apostrophe
from the string.

On the other hand, you can't delete things with regular expressions.

If you want to delete the first apostrophe, you can s/'//.

Kragen
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Tue Sep 14 1999
55 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


------------------------------

Date: Wed, 15 Sep 1999 19:17:16 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: How to match with m/$variable/ ??
Message-Id: <0hSD3.13262$N77.956658@typ11.nn.bcandid.com>

In article <7roph7$1a8$1@sunburst.ccs.yorku.ca>,
Michael Friendly <friendly@hotspur.psych.yorku.ca> wrote:
>I've obviously forgotten something, because I can't get variable patterns
>to work in matches.  E.g., I want to use
>
># Patterns for include-type statements, leaving filename in #1
>$include_pat = join('|',
>      ('\\input\b\{?(\S+)\}',
>       '\\include\s*\{(\S+)\}'
>      ));

perl -e "print '\\\\', qq(\n)" outputs
\
 . . . i.e. \\ in '' becomes \.  So by the time the regex sees it, it 
thinks it's looking for \i, not \ followed by i.  (What's \i?)

HTH.
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Tue Sep 14 1999
55 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


------------------------------

Date: Wed, 15 Sep 1999 15:50:19 -0400
From: "Robert W. Byrd" <tech@tburg.net>
Subject: Re: How to validate a URL?
Message-Id: <37DFF87A.E960932D@tburg.net>

Abigail wrote:

Amazing Abigail, just amazing!

> Paul Carter (couton@bigfoot.com) wrote on MMCCVI September MCMXCIII in
> <URL:news:xMND3.25$68.352@news2-hme0>:
> &&
> && The main problem is that I am unable to validate a URL
> && As far as I can see, the requirements for a WWW URL would be a "http://" and
> && a "." (period)
>
> Validating URLs isn't that hard. The following regex should work.
> It's a tad more complicated than looking for 'http://' and a dot
> though.
>
> m<
> (?:http://(?:(?:(?:(?:(?:[a-zA-Z\d](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?)\.

--
Robert W. Byrd | Completely Computer Friendly
tech@tburg.net | 67-B Oxford St., Tillsonburg, ON CA N4G 2G3
------------------------------------------------------------
We are dyslexic of Borg; prepare to have your ass laminated.





------------------------------

Date: Wed, 15 Sep 1999 12:05:38 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: perl to shell
Message-Id: <37DFEE02.17873985@cisco.com>

[ Mei wrote:

> I would like to incorporate some of my perl scripts in one shell script.  So
> when I use “pipeline.sh”, my data will go through perl scripts one by one.
> How do I do that?

Connect them using pipes. If for example your scripts
are named p1.pl , p2.pl and p3.pl then

#!/usr/bin/sh
whatevercommand | p1.pl  | p2.pl  | p3.pl

will do the trick.
==



------------------------------

Date: 15 Sep 1999 14:49:43 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Sendmail: Address family not supported by protocol family
Message-Id: <slrn7tvu7n.hj3.abigail@alexandra.delanet.com>

Ron Hamersma (rhamersma@intermodulair.nl) wrote on MMCCVI September
MCMXCIII in <URL:news:INTR40436D716@intermodulair.nl>:
'' Hi, I am new to Perl,
'' am using Perl sendmail program,
'' which uses SMTP

That must be sendmail 9.0 - the Perl rewrite, right?

'' now when the program is called I get the following error message:
'' 
'' Could not connect to server (Address family not supported by protocol
'' family).

Did you find it in 'man perldiag'? If it's not there, it's not a Perl
error message. It might however be a system error message; check your
<sys/errno.h> file.

'' which is strange, can anybody shed some light on this curious message?

Why is that strange?



Abigail
-- 
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
             "\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
             "\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


------------------------------

Date: Wed, 15 Sep 1999 15:46:30 -0400
From: "David Harris" <dharris@drh.net>
Subject: The DB_File locking method is flawed
Message-Id: <CISD3.1555$zI3.41304@iad-read.news.verio.net>

Hi,

I've been doing some work with the DB_File module and mod_perl and I've
found a bug in the "commonly accepted" procedure for locking a database
file. This procedure is outlined in the POD documentation for the DB_File
module and in the Programming Perl book where it covers the DB_File module
and other examples and guides. The bug can lead to database corruption.

The example locking method goes like this:

    $db = tie(%db, 'DB_File', '/tmp/foo.db', O_CREAT|O_RDWR, 0644)
        || die "dbcreat /tmp/foo.db $!";
    $fd = $db->fd;
    open(DB_FH, "+<&=$fd") || die "dup $!";
    flock (DB_FH, LOCK_SH) || die "flock: $!";

The problem is that the database file is opened and then later locked -- and
when the database is opened the first 4k (in my dbm library) are read and
then cached in memory. Therefore, a process can open the database file and
cache the first 4k, then block in the flock while another process modifies
the first 4k of the file. When the original process gets the lock is now has
a inconsistent view of the database, and if it writes using this inconstant
view, it may corrupt the database on disk.

This does not cause corruption every time a process has to block in the
flock call, because one can do quite a bit of writing to the database file
without actually changing the first 4k of the file.

I first saw this problem when I investigated using strace to see a listing
of all the system calls. I have verified that the tie line not only produces
an open system call, but also a read system call on the database file.

To be sure of the problem, I've created an example program shows database
corruption on disk when using this locking method. It simply forks off two
processes. The first gets the lock and writes a bunch of records to the
database, while the second blocks in the flock call. Then the first process
finishes and the second writes a bunch of records. When the second process
is done, most of the records written by the first process are no longer in
the database. Stas Beckman (author of the mod_perl guide) has looked at the
program and verified that he is also seeing corruption.

My example program, along with some documentation and the system call trace
are available in this archive:

http://www.davideous.com/misc/dblockflaw-1.2.tar.gz
http://www.davideous.com/misc/dblockflaw-1.2/

I believe that the correct fix for this problem is to simply gain a lock
before letting DB_File touch the database file. For my own work, I've
created a module to this effect called DRH::DB_Wrap which wraps the DB_File
module and adds one argument to the tie command, which specifies what
locking should be done, "read" or "write". IHMO, this is a nice solution for
the locking problem, and I'm wondering if it would be useful to others. I'd
be glad to formally package it up (of course removing my internal "DRH::"
prefix) if people think this would be useful.

You can get a copy of this DRH::DB_Wrap module at:

http://www.davideous.com/misc/DB_Wrap.pm

I'm looking forward to seeing this get fixed.

 - David Harris
   Principal Engineer, DRH Internet Services





------------------------------

Date: Wed, 15 Sep 1999 19:07:29 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: trimming spaces from a string
Message-Id: <R7SD3.13251$N77.956485@typ11.nn.bcandid.com>

In article <slrn7tv1d2.1pj.*@dragons.duesouth.net>,
Matthew Bafford <*@dragons.duesouth.net> wrote:
>On Wed, 15 Sep 1999 17:29:34 GMT, hoz@rocketmail.com (hoz) spewed forth: 
>: to trim spaces from a string try:
>: $string =~ s/\s//g;

(It should be noted that the original poster wasn't clear on whether
they wanted to trim spaces at the beginning and end of the string, or
everywhere.)

>This is, in the current regex implementation, less efficient than
>necessary.  A simple change:
>    s/\s+//g
>does wonders.
>The fastest solution is, by far, using tr:
>    tr[ \n\r\f\b][]d;
>I tend to use s///g for that reason.  Also, I worry about optimizations
>AFTER my code is written.  More often than not, I find s////g vs tr///
>optimizations don't matter.  When they do, I use tr///.

Well, I figured you must have done some benchmarking to make statements
about the relative magnitudes of the performance differences.  It looks
like I was right -- but you're not necessarily right about the s/// in
all cases.

Here are my benchmarks.

Benchmark: timing 100000 iterations of delete_with_s $interspersedstring, delete_with_s $whitespacestring, delete_with_s_star $interspersedstring, delete_with_s_star $whitespacestring, delete_with_tr $interspersedstring, delete_with_tr $whitespacestring, nop $interspersedstring, nop $whitespacestring...
delete_with_s $interspersedstring: 51 wallclock secs (41.17 usr +  0.00 sys = 41.17 CPU)
delete_with_s $whitespacestring: 52 wallclock secs (37.08 usr +  0.00 sys = 37.08 CPU)
delete_with_s_star $interspersedstring: 80 wallclock secs (52.34 usr +  0.00 sys = 52.34 CPU)
delete_with_s_star $whitespacestring:  9 wallclock secs ( 7.11 usr +  0.01 sys =  7.12 CPU)
delete_with_tr $interspersedstring: 13 wallclock secs ( 9.08 usr +  0.00 sys =  9.08 CPU)
delete_with_tr $whitespacestring:  9 wallclock secs ( 6.57 usr +  0.00 sys =  6.57 CPU)
nop $interspersedstring:  5 wallclock secs ( 3.65 usr +  0.00 sys =  3.65 CPU)
nop $whitespacestring:  3 wallclock secs ( 3.07 usr +  0.00 sys =  3.07 CPU)

I should have called delete_with_s_star delete_with_s_plus.  Oops.

Looks like s/\s+//g is slower than s/\s//g in the worst case (where all
occurrences of \s+ are just \s) as you might expect, but about five
times faster in the best case -- just as fast as tr.  Also, it looks
like s/\s//g's time is dominated by doing the many replacements, not by
scanning; $interspersedstring is twice as long as $whitespacestring,
but contains the same number of spaces.

tr (and s/\s*//g on the all-whitespace string) was so fast the overhead
of procedure calling was significant.

Here's the script.

#!/usr/bin/perl -w
use strict;
use Benchmark;
my $whitespacestring = " " x 100;
my $interspersedstring = " x" x 100;

sub nop {
	my ($s) = @_;
	return $s;
}

sub delete_with_s {
	my ($s) = @_;
	$s =~ s/\s//g;
	return $s;
}

sub delete_with_s_star {
	my ($s) = @_;
	$s =~ s/\s+//g;
	return $s;
}

sub delete_with_tr {
	my ($s) = @_;
	$s =~ tr[ \t\n\v\r\f\b][]d;
	return $s;
}

my @strings = qw($whitespacestring $interspersedstring);
my @routines = qw(nop delete_with_s delete_with_s_star delete_with_tr);
my %codeblocks = map { $_ => eval "sub { $_ }" } 
	map { 
		my $routine = $_;
		map { "$routine $_" } @strings
	} @routines;

# print keys %codeblocks;

timethese(100_000, \%codeblocks);

__END__

I'm on a 
SunOS kirk 5.6 Generic_105181-13 sun4m sparc SUNW,SPARCstation-20
with
Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:
  Platform:
    osname=solaris, osvers=2.6, archname=sun4-solaris
    uname='sunos shadow 5.6 generic sun4m sparc sunw,sparcstation-20 '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useperlio=undef d_sfio=undef
  Compiler:
    cc='gcc', optimize='-O', gccversion=2.8.1
    cppflags='-I/usr/local/include'
    ccflags ='-I/usr/local/include'
    stdchar='unsigned char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    alignbytes=8, usemymalloc=y, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib /usr/ccs/lib
    libs=-lsocket -lnsl -lgdbm -ldl -lm -lc -lcrypt
    libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
    cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib'


Characteristics of this binary (from libperl): 
  Built under solaris
  Compiled at May 17 1999 23:47:08
  @INC:
    /usr/local/lib/perl5/5.00503/sun4-solaris
    /usr/local/lib/perl5/5.00503
    /usr/local/lib/perl5/site_perl/5.005/sun4-solaris
    /usr/local/lib/perl5/site_perl/5.005
    .

-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Tue Sep 14 1999
55 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


------------------------------

Date: Wed, 15 Sep 1999 13:47:42 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: trimming spaces from a string
Message-Id: <x3ywvtsdq2p.fsf@tigre.matrox.com>


kragen@dnaco.net (Kragen Sitaker) writes:

> In article <7rmr41$4lv$1@bgtnsc01.worldnet.att.net>,
> Dolly & Will Cardwell <wellhaven@worldnet.att.net> wrote:
> >$s='   aa   bcdef      ';
> >$t='aa  bcdef';
> 
> $s =~ s/^\s*(.*?)\s*$/$1/;

That doesn't solve the problem. $s is still not the same as $t. You
also need:

	$t =~ s/^\s+|\s+$/g;	# just in case
	$s =~ s/\s+/ /g;
	$t =~ s/\s+/ /g;
	

--Ala



------------------------------

Date: Wed, 15 Sep 1999 13:53:23 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: trimming spaces from a string
Message-Id: <x3yvh9cdpt8.fsf@tigre.matrox.com>


"Dolly & Will Cardwell" <wellhaven@worldnet.att.net> writes:

> $s='   aa   bcdef      ';
> $t='aa  bcdef';
> 
> # I'd like them to match.
> # That is, I want to match as though leading and and trailing spaces were
> removed.

	print "match" if join(' ' => split ' ' => $s) eq 
	                 join(' ' => split ' ' => $t);

> $s='abc*def  * ghi';
> $sep='*';  # $sep may vary, and asterisk is a candidate.
> @flds=split /$sep/, $s;  # This won't split on * but works for non-spcl
> chars

@flds = split /\Q$sep/ => $s;

checkout perlre for more info on \Q.

HTH,
--Ala



------------------------------

Date: Wed, 15 Sep 1999 12:42:30 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: trimming spaces from a string
Message-Id: <MPG.1249967f3f18c50989f6c@nntp.hpl.hp.com>

In article <slrn7tvkgj.hdt.gabor@vnode.vmunix.com> on 15 Sep 1999 
13:06:27 -0400, Gabor <gabor@vmunix.com> says...
> In comp.lang.perl.misc, Larry Rosler <lr@hpl.hp.com> wrote :
> # In article <slrn7tvfm6.gtr.gabor@vnode.vmunix.com> on 15 Sep 1999 
> # 11:44:06 -0400, Gabor <gabor@vmunix.com> says...
 ...
> # > I wasn't trying to give a fool-proof solution but a start. ;)
> # 
> # Even with that knowledge, my PSI::ESP module failed to detect any 
> # tentativeness in your response.  Maybe posting conjectures before 
> # thousands of readers, without identifying them as such and without 
> # testing them at all, is a poor idea.
> 
> Well, I would never trust anyone's code posted here.  Even the so
> called 'gurus' have posted crap here before, or code that didn't quite
> work.  Covering all possible scenarios was left to the person asking
> the question.  I offered something can serve as a start.  If he, or
> you, don't like it, you can offer something better. ;)

I did.  Look back a few in this subthread.  I posted a solution that was 
tested, and that worked.  It took time to write it and to test it, time 
for which no one will pay me.

Most of us here take professional responsibility for the responses we 
post.  Those who don't are likely to end up in the killfiles of the 
knowledgeable.  Unfortunately, that doesn't protect the innocent from 
irresponsible answers.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: Wed, 15 Sep 1999 12:56:48 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: trimming spaces from a string
Message-Id: <MPG.124999d93ff9d240989f6d@nntp.hpl.hp.com>

In article <R7SD3.13251$N77.956485@typ11.nn.bcandid.com> on Wed, 15 Sep 
1999 19:07:29 GMT, Kragen Sitaker <kragen@dnaco.net> says...
 ...
> sub delete_with_tr {
> 	my ($s) = @_;
> 	$s =~ tr[ \t\n\v\r\f\b][]d;
> 	return $s;
> }

"\v" (vertical tab) is defined in C, but not in Perl.

"\b" (backspace) is not a white-space character in either language.

None of that affects the benchmark, of course.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

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" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. 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" from
almanac@ruby.oce.orst.edu. 

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 808
*************************************


home help back first fref pref prev next nref lref last post