[29697] in Perl-Users-Digest
Perl-Users Digest, Issue: 941 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 16 14:10:14 2007
Date: Tue, 16 Oct 2007 11:09:08 -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 Tue, 16 Oct 2007 Volume: 11 Number: 941
Today's topics:
Re: "copy" from File::Copy fails but returns success <ben@morrow.me.uk>
Inline regex <steve@nospamtoday.com>
Re: Inline regex <simon.chao@fmr.com>
Re: Inline regex <abigail@abigail.be>
Re: Inline regex <uri@stemsystems.com>
Re: Inline regex <thepoet_nospam@arcor.de>
Re: Inline regex <steve@nospamtoday.com>
Re: Inline regex <glex_no-spam@qwest-spam-no.invalid>
Re: Inline regex <steve@nospamtoday.com>
Re: Inline regex <steve@nospamtoday.com>
Re: Inline regex <steve@nospamtoday.com>
Re: Inline regex <mritty@gmail.com>
Re: Inline regex <simon.chao@fmr.com>
Re: Inline regex <nobull67@gmail.com>
Re: Inline regex <nobull67@gmail.com>
Re: Inline regex <simon.chao@fmr.com>
Re: Inline regex <simon.chao@fmr.com>
Re: Inline regex <thepoet_nospam@arcor.de>
Re: jabba the tuh <jurgenex@hotmail.com>
Re: jabba the tuh <jurgenex@hotmail.com>
Re: Perl threads + HTTPS = Crash :( <ben@morrow.me.uk>
Question about simple databases in Perl <january.weiner@gmail.com>
Re: Question about simple databases in Perl <mritty@gmail.com>
Re: Question about simple databases in Perl xhoster@gmail.com
Re: Setting perl's output buffer size <ben@morrow.me.uk>
Re: Strong Blog CGI in Perl <cwilbur@chromatico.net>
Re: Strong Blog CGI in Perl <izidoor@invalid.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 16 Oct 2007 14:35:40 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: "copy" from File::Copy fails but returns success
Message-Id: <careu4-3i1.ln1@osiris.mauzo.dyndns.org>
Quoth Paul Lalli <mritty@gmail.com>:
> On Oct 16, 4:43 am, Henry Law <n...@lawshouse.org> wrote:
>
> > My problem is that the use of "copy" from File::Copy appears to
> > succeed (with a TRUE return code) but then when I go to
> > uncompress the file it's not there.
> >
> > Because of the CGI environment it's hard to give a fully-runnable
> > fragment, but here's the core of it.
> >
> > $rc = copy ("/home/nfb/temp.txt", "/tmp/nfb");
> > my $output = "Return code:$rc<br>" . `ls -l /tmp/nfb`;
> > print "Content-type:
> > text/html\n\n<html><body><p>$output</p></body></html>\n";
> > exit 0;
> >
> > The source file exists and is chmod 777. The result from the
> > code above is
> >
> > Return code:1
> > -rw-r--r-- 1 apache apache 5 Oct 16 09:34 /tmp/nfb
> >
> > ... which shows that the copy succeeded (return code 1) but the
> > file is nevertheless not in the target directory /tmp/nfb. I'm
> > baffled.
>
> Look at that ls output again. See that first dash? That means that /
> tmp/nfb is a file, not a directory. You copied the file /home/nfb/
> temp.txt to the *file* /tmp/nfb.
>
> If a directory named /tmp/nfb does not already exist, then you need to
> create it first:
> unless (-e "/tmp/nfb") {
> mkdir "/tmp/nfb" or die $!;
> }
Better would be
my $dir = '/tmp/nfb';
-e $dir and ! -d $dir and unlink $dir
or die "can't unlink $dir: $!";
-d $dir or mkdir $dir
or die "can't mkdir $dir: $!";
which has the same race condition, but is proof against old copies of
the file hanging around.
Ben
------------------------------
Date: Tue, 16 Oct 2007 15:18:36 GMT
From: steve <steve@nospamtoday.com>
Subject: Inline regex
Message-Id: <fD4Ri.179368$TR1.165419@fe06.news.easynews.com>
Hi all,
I am currently working on a small script that parses text files and
outputs them in a different format, to be used by another program. I am
constantly removing trailing whitespace like so:
$desc = $line[7]; # @line is an array derived from a line in a CSV file
$desc =~ s/\s+$//g; # Trim trailing whitespace
But this is in two lines. How can I copy the variable and remove
whitespace in one line of code?
I know I don't need to, but I tried and failed and now am curious.
Thanks
steve
------------------------------
Date: Tue, 16 Oct 2007 15:22:48 -0000
From: it_says_BALLS_on_your forehead <simon.chao@fmr.com>
Subject: Re: Inline regex
Message-Id: <1192548168.011614.43480@v23g2000prn.googlegroups.com>
On Oct 16, 11:18 am, steve <st...@nospamtoday.com> wrote:
> Hi all,
>
> I am currently working on a small script that parses text files and
> outputs them in a different format, to be used by another program. I am
> constantly removing trailing whitespace like so:
>
> $desc = $line[7]; # @line is an array derived from a line in a CSV file
> $desc =~ s/\s+$//g; # Trim trailing whitespace
>
> But this is in two lines. How can I copy the variable and remove
> whitespace in one line of code?
if you're concerned with brevity of code, you could always use a map.
e.g.
my @trimmed = map { s/\s+$// } @line;
------------------------------
Date: 16 Oct 2007 15:26:50 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: Inline regex
Message-Id: <slrnfh9m1q.roo.abigail@alexandra.abigail.be>
_
steve (steve@nospamtoday.com) wrote on VCLIX September MCMXCIII in
<URL:news:fD4Ri.179368$TR1.165419@fe06.news.easynews.com>:
}} Hi all,
}}
}} I am currently working on a small script that parses text files and
}} outputs them in a different format, to be used by another program. I am
}} constantly removing trailing whitespace like so:
}}
}} $desc = $line[7]; # @line is an array derived from a line in a CSV file
}} $desc =~ s/\s+$//g; # Trim trailing whitespace
}}
}} But this is in two lines. How can I copy the variable and remove
}} whitespace in one line of code?
I'd leave it as is.
Or, if I have to write it in one line, my first preference would be:
$desc = $line [7]; $desc =~ s/\s+$//; # No need for /g.
Second choice:
($desc = $line [7]) =~ s/\s+$//; # No need for /g.
Abigail
--
perl -wle '$, = " "; sub AUTOLOAD {($AUTOLOAD =~ /::(.*)/) [0];}
print+Just (), another (), Perl (), Hacker ();'
------------------------------
Date: Tue, 16 Oct 2007 15:30:53 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Inline regex
Message-Id: <x764176pqq.fsf@mail.sysarch.com>
>>>>> "isBoyf" == it says BALLS on your forehead <simon.chao@fmr.com> writes:
>> $desc = $line[7]; # @line is an array derived from a line in a CSV file
>> $desc =~ s/\s+$//g; # Trim trailing whitespace
>>
>> But this is in two lines. How can I copy the variable and remove
>> whitespace in one line of code?
isBoyf> if you're concerned with brevity of code, you could always use a map.
isBoyf> my @trimmed = map { s/\s+$// } @line;
hmm, have you tested that? i don't think you will like the results.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 16 Oct 2007 17:37:01 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Inline regex
Message-Id: <4714da9d$0$16100$9b4e6d93@newsspool1.arcor-online.net>
steve wrote:
> I am currently working on a small script that parses text files and
> outputs them in a different format, to be used by another program. I am
> constantly removing trailing whitespace like so:
>
> $desc = $line[7]; # @line is an array derived from a line in a CSV file
> $desc =~ s/\s+$//g; # Trim trailing whitespace
>
> But this is in two lines. How can I copy the variable and remove
> whitespace in one line of code?
>
> I know I don't need to, but I tried and failed and now am curious.
If you want to do the assignment and replacement in one line, you'll
just have to consider operator precedence as diplayed in "perldoc
perlop". The regex comparison operator "=~" binds tighter than
the simple assignment "=", therefore a simple
my $desc = $line[7] =~ s/\s+$//;
won't do that and rather assign the result of the regex replacement
to $desc (btw., no need for the /g modifier there, you already take
care of multiple spaces with the greedy + multiplier). However, simple
brackets suffice to tell perl the order of processing you want:
(my $desc = $line[7]) =~ s/\s+$//;
That's about as short as one can make it.
-Chris
------------------------------
Date: Tue, 16 Oct 2007 15:51:55 GMT
From: steve <steve@nospamtoday.com>
Subject: Re: Inline regex
Message-Id: <4714DE19.10706@nospamtoday.com>
Christian Winter wrote:
> steve wrote:
>> I am currently working on a small script that parses text files and
>> outputs them in a different format, to be used by another program. I
>> am constantly removing trailing whitespace like so:
>>
>> $desc = $line[7]; # @line is an array derived from a line in a CSV
>> file
>> $desc =~ s/\s+$//g; # Trim trailing whitespace
>>
>> But this is in two lines. How can I copy the variable and remove
>> whitespace in one line of code?
>>
>> I know I don't need to, but I tried and failed and now am curious.
>
> If you want to do the assignment and replacement in one line, you'll
> just have to consider operator precedence as diplayed in "perldoc
> perlop". The regex comparison operator "=~" binds tighter than
> the simple assignment "=", therefore a simple
>
> my $desc = $line[7] =~ s/\s+$//;
>
> won't do that and rather assign the result of the regex replacement
> to $desc (btw., no need for the /g modifier there, you already take
> care of multiple spaces with the greedy + multiplier). However, simple
> brackets suffice to tell perl the order of processing you want:
>
> (my $desc = $line[7]) =~ s/\s+$//;
>
> That's about as short as one can make it.
>
> -Chris
Wow, thanks for the quick response!
Would the code you suggested remove the whitespace from $line[7] as well?
steve
------------------------------
Date: Tue, 16 Oct 2007 11:15:36 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Inline regex
Message-Id: <4714e3a8$0$507$815e3792@news.qwest.net>
steve wrote:
[...]
> Wow, thanks for the quick response!
>
> Would the code you suggested remove the whitespace from $line[7] as well?
ahhhh. Why not try it and see for yourself?
------------------------------
Date: Tue, 16 Oct 2007 16:17:50 GMT
From: steve <steve@nospamtoday.com>
Subject: Re: Inline regex
Message-Id: <4714E429.2010809@nospamtoday.com>
Christian Winter wrote:
> steve wrote:
>> I am currently working on a small script that parses text files and
>> outputs them in a different format, to be used by another program. I
>> am constantly removing trailing whitespace like so:
>>
>> $desc = $line[7]; # @line is an array derived from a line in a CSV
>> file
>> $desc =~ s/\s+$//g; # Trim trailing whitespace
>>
>> But this is in two lines. How can I copy the variable and remove
>> whitespace in one line of code?
>>
>> I know I don't need to, but I tried and failed and now am curious.
>
> If you want to do the assignment and replacement in one line, you'll
> just have to consider operator precedence as diplayed in "perldoc
> perlop". The regex comparison operator "=~" binds tighter than
> the simple assignment "=", therefore a simple
>
> my $desc = $line[7] =~ s/\s+$//;
>
> won't do that and rather assign the result of the regex replacement
> to $desc (btw., no need for the /g modifier there, you already take
> care of multiple spaces with the greedy + multiplier). However, simple
> brackets suffice to tell perl the order of processing you want:
>
> (my $desc = $line[7]) =~ s/\s+$//;
>
> That's about as short as one can make it.
>
> -Chris
Wow, thanks for the quick response, that works nicely.
Another quick question...
I have a variable that is padded with leading zeros (e.g. "0001.125"). I
want to be able to remove all leading zeros if the value >= 1 ("1.125"),
but leave one leading zero if the value < 1 (e.g. "0000.125" should
become "0.125" not ".125"). Can I do this with one regex?
------------------------------
Date: Tue, 16 Oct 2007 16:18:14 GMT
From: steve <steve@nospamtoday.com>
Subject: Re: Inline regex
Message-Id: <9v5Ri.161448$6L.155799@fe03.news.easynews.com>
Christian Winter wrote:
> steve wrote:
>> I am currently working on a small script that parses text files and
>> outputs them in a different format, to be used by another program. I
>> am constantly removing trailing whitespace like so:
>>
>> $desc = $line[7]; # @line is an array derived from a line in a CSV
>> file
>> $desc =~ s/\s+$//g; # Trim trailing whitespace
>>
>> But this is in two lines. How can I copy the variable and remove
>> whitespace in one line of code?
>>
>> I know I don't need to, but I tried and failed and now am curious.
>
> If you want to do the assignment and replacement in one line, you'll
> just have to consider operator precedence as diplayed in "perldoc
> perlop". The regex comparison operator "=~" binds tighter than
> the simple assignment "=", therefore a simple
>
> my $desc = $line[7] =~ s/\s+$//;
>
> won't do that and rather assign the result of the regex replacement
> to $desc (btw., no need for the /g modifier there, you already take
> care of multiple spaces with the greedy + multiplier). However, simple
> brackets suffice to tell perl the order of processing you want:
>
> (my $desc = $line[7]) =~ s/\s+$//;
>
> That's about as short as one can make it.
>
> -Chris
Wow, thanks for the quick response, that works nicely.
Another quick question...
I have a variable that is padded with leading zeros (e.g. "0001.125"). I
want to be able to remove all leading zeros if the value >= 1 ("1.125"),
but leave one leading zero if the value < 1 (e.g. "0000.125" should
become "0.125" not ".125"). Can I do this with one regex?
------------------------------
Date: Tue, 16 Oct 2007 16:24:48 GMT
From: steve <steve@nospamtoday.com>
Subject: Re: Inline regex
Message-Id: <jB5Ri.161507$6L.100502@fe03.news.easynews.com>
steve wrote:
> Christian Winter wrote:
>> steve wrote:
>>> I am currently working on a small script that parses text files and
>>> outputs them in a different format, to be used by another program. I
>>> am constantly removing trailing whitespace like so:
>>>
>>> $desc = $line[7]; # @line is an array derived from a line in a CSV
>>> file
>>> $desc =~ s/\s+$//g; # Trim trailing whitespace
>>>
>>> But this is in two lines. How can I copy the variable and remove
>>> whitespace in one line of code?
>>>
>>> I know I don't need to, but I tried and failed and now am curious.
>>
>> If you want to do the assignment and replacement in one line, you'll
>> just have to consider operator precedence as diplayed in "perldoc
>> perlop". The regex comparison operator "=~" binds tighter than
>> the simple assignment "=", therefore a simple
>>
>> my $desc = $line[7] =~ s/\s+$//;
>>
>> won't do that and rather assign the result of the regex replacement
>> to $desc (btw., no need for the /g modifier there, you already take
>> care of multiple spaces with the greedy + multiplier). However, simple
>> brackets suffice to tell perl the order of processing you want:
>>
>> (my $desc = $line[7]) =~ s/\s+$//;
>>
>> That's about as short as one can make it.
>>
>> -Chris
>
> Wow, thanks for the quick response, that works nicely.
>
> Another quick question...
> I have a variable that is padded with leading zeros (e.g. "0001.125"). I
> want to be able to remove all leading zeros if the value >= 1 ("1.125"),
> but leave one leading zero if the value < 1 (e.g. "0000.125" should
> become "0.125" not ".125"). Can I do this with one regex?
Apologies for the duplicate posts, thunderbird is being a benny...
------------------------------
Date: Tue, 16 Oct 2007 09:30:54 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Inline regex
Message-Id: <1192552254.419229.236940@t8g2000prg.googlegroups.com>
On Oct 16, 12:17 pm, steve <st...@nospamtoday.com> wrote:
> I have a variable that is padded with leading zeros
> (e.g. "0001.125"). I want to be able to remove all leading zeros
> if the value >= 1 ("1.125"), but leave one leading zero if the
> value < 1 (e.g. "0000.125" should become "0.125" not ".125"). Can
> I do this with one regex?
You can, with look-aheads:
$x =~ s/^0+(?!\.)//;
But depending on your data, sprintf() might be simpler.
$x = sprintf('%.3f', $x);
Or, just tell Perl that it really is a number, which might be simpler
still:
$x += 0;
Paul Lalli
------------------------------
Date: Tue, 16 Oct 2007 16:51:36 -0000
From: it_says_BALLS_on_your forehead <simon.chao@fmr.com>
Subject: Re: Inline regex
Message-Id: <1192553496.480584.261420@v29g2000prd.googlegroups.com>
On Oct 16, 11:30 am, Uri Guttman <u...@stemsystems.com> wrote:
> >>>>> "isBoyf" == it says BALLS on your forehead <simon.c...@fmr.com> writes:
>
> >> $desc = $line[7]; # @line is an array derived from a line in a CSV file
> >> $desc =~ s/\s+$//g; # Trim trailing whitespace
> >>
> >> But this is in two lines. How can I copy the variable and remove
> >> whitespace in one line of code?
>
> isBoyf> if you're concerned with brevity of code, you could always use a map.
>
> isBoyf> my @trimmed = map { s/\s+$// } @line;
>
> hmm, have you tested that? i don't think you will like the results.
stupid mistake :-(.
my @trimmed = map { s/\s+$//; $_ } @line;
------------------------------
Date: Tue, 16 Oct 2007 17:14:06 -0000
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: Inline regex
Message-Id: <1192554846.495504.129670@t8g2000prg.googlegroups.com>
On Oct 16, 4:26 pm, Abigail <abig...@abigail.be> wrote:
> Or, if I have to write it in one line, my first preference would be:
>
> $desc = $line [7]; $desc =~ s/\s+$//; # No need for /g.
>
> Second choice:
>
> ($desc = $line [7]) =~ s/\s+$//; # No need for /g.
>
If you really don't like the above format I have some syntactic sugar
for you.
use List::MoreUtils qw ( apply );
my $desc = apply { s/\s+$// } $line[7];
------------------------------
Date: Tue, 16 Oct 2007 17:14:57 -0000
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: Inline regex
Message-Id: <1192554897.889749.133860@t8g2000prg.googlegroups.com>
On Oct 16, 5:51 pm, it_says_BALLS_on_your forehead
<simon.c...@fmr.com> wrote:
> On Oct 16, 11:30 am, Uri Guttman <u...@stemsystems.com> wrote:
> isBoyf> my @trimmed = map { s/\s+$// } @line;
>
> > hmm, have you tested that? i don't think you will like the results.
>
> stupid mistake :-(.
>
> my @trimmed = map { s/\s+$//; $_ } @line;
That still modifies @line.
------------------------------
Date: Tue, 16 Oct 2007 17:28:34 -0000
From: it_says_BALLS_on_your forehead <simon.chao@fmr.com>
Subject: Re: Inline regex
Message-Id: <1192555714.131736.35490@v23g2000prn.googlegroups.com>
On Oct 16, 1:14 pm, Brian McCauley <nobul...@gmail.com> wrote:
> On Oct 16, 5:51 pm, it_says_BALLS_on_your forehead
>
> <simon.c...@fmr.com> wrote:
> > On Oct 16, 11:30 am, Uri Guttman <u...@stemsystems.com> wrote:
> > isBoyf> my @trimmed = map { s/\s+$// } @line;
>
> > > hmm, have you tested that? i don't think you will like the results.
>
> > stupid mistake :-(.
>
> > my @trimmed = map { s/\s+$//; $_ } @line;
good grief! :-)
my @trimmed = map { my $val = $_; $val =~ s/\s+$//; $val } @line;
------------------------------
Date: Tue, 16 Oct 2007 17:32:21 -0000
From: it_says_BALLS_on_your forehead <simon.chao@fmr.com>
Subject: Re: Inline regex
Message-Id: <1192555941.923278.201200@y27g2000pre.googlegroups.com>
On Oct 16, 1:28 pm, it_says_BALLS_on_your forehead
<simon.c...@fmr.com> wrote:
> On Oct 16, 1:14 pm, Brian McCauley <nobul...@gmail.com> wrote:
>
> > On Oct 16, 5:51 pm, it_says_BALLS_on_your forehead
>
> > <simon.c...@fmr.com> wrote:
> > > On Oct 16, 11:30 am, Uri Guttman <u...@stemsystems.com> wrote:
> > > isBoyf> my @trimmed = map { s/\s+$// } @line;
>
> > > > hmm, have you tested that? i don't think you will like the results.
>
> > > stupid mistake :-(.
>
> > > my @trimmed = map { s/\s+$//; $_ } @line;
>
> good grief! :-)
>
> my @trimmed = map { my $val = $_; $val =~ s/\s+$//; $val } @line;
OR, if you WANT to change the original @line:
map { s/\s+$// } @line;
(not sure, but i believe that map in void context is fine in >= 5.8.7,
correct?)
------------------------------
Date: Tue, 16 Oct 2007 19:49:46 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Inline regex
Message-Id: <4714f98b$0$16113$9b4e6d93@newsspool1.arcor-online.net>
it_says_BALLS_on_your forehead schrieb:
>
> OR, if you WANT to change the original @line:
>
> map { s/\s+$// } @line;
>
> (not sure, but i believe that map in void context is fine in >= 5.8.7,
> correct?)
I tend to shun a map without use of its return values like
the devil the holy water, as the same can be accomplished
with a for loop, and the intention is clearer to whoever
gets to maintain my code.
s/\s+$// for @line;
-Chris
------------------------------
Date: Tue, 16 Oct 2007 17:27:59 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: jabba the tuh
Message-Id: <zw6Ri.1098$HU1.529@trndny07>
Michele Dondi wrote:
> On 3 Oct 2007 21:24:17 GMT, Glenn Jackman <glennj@ncf.ca> wrote:
>
>>> How does one type these numbers with the ppl? How many types are
>>> there in the ppl? Leave out anything more than two levels of
>>> indirection on
>>
>> Lots of regulars here bristle unless you talk about Perl or perl. My
>> suggestion is to suck it up and write "Perl" and not "the ppl".
>
> Yeah... also, "ppl" is one char less than either "perl" or "Perl". But
> "the ppl" is three more. I don't really see what's the advantage of
> using that spelling that no other one is familiar with, and is likely
> to confuse so many people.
No, not confusing at all. After all ppl is clearly the abbreviation for
Private Pilot License. Although I have no idea what a PPL has possibly to do
with this NG.
Oh, and I believe in some baby talk it stands for 'people', too. Although
"how does one type these numbers with the people?" or "how many types are
there in the people?" doesn't make much sense to me, either.
jue
------------------------------
Date: Tue, 16 Oct 2007 17:34:03 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: jabba the tuh
Message-Id: <fC6Ri.4670$Oy1.936@trndny08>
Wade Ward wrote:
[...]
> comment3) My output for this is:
[...]
> jabba the tuh from "Wade Ward" zaxfuuq@invalid.net
> question 1) How do I use the ppl to get "jabba the hut" as output.
I have no idea how to use either a Private Pilot License (PPL) or the people
(ppl) to get that output.
However in Perl you could just split() on the space and then reverse() the
last substring to convert 'tuh' to 'hut'.
jue
------------------------------
Date: Tue, 16 Oct 2007 14:27:53 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Perl threads + HTTPS = Crash :(
Message-Id: <prqeu4-3e1.ln1@osiris.mauzo.dyndns.org>
Quoth Dan <danett18@yahoo.com.br>:
>
> I have a program in perl which do several HTTP requests, so I
> implemented some threads to get it running more fast, in general I use
> 5 threads at the same time.
>
> The program work perfectly when i'm requesting only HTTP pages with
> multiple threads, however when I change HTTP to HTTPS with multiple
> threads the program crash (segmentation fault / access violation). If
> I use HTTPS and only one thread the program work perfectly. :(
>
> That's looks like really strange for me, which come to my mind is that
> HTTPS is not thread safe in perl?
It looks to me as though Crypt::SSLeay is not thread-safe. OpenSSL
itself can be thread-safe, but Crypt::SSLeay doesn't appear to call the
functions required to set up multithreaded access. Note that this is
just from a quick glance through the code: I don't have any real
knowledge of either OpenSSL or Crypt::SSLeay's internals. You could try
filing a bug against Crypt::SSLeay.
Ben
------------------------------
Date: Tue, 16 Oct 2007 16:30:59 +0200 (CEST)
From: January Weiner <january.weiner@gmail.com>
Subject: Question about simple databases in Perl
Message-Id: <ff2hv3$vm2$2@sagnix.uni-muenster.de>
Hello,
I have the following problem:
I have a very simple relation keyword -- number. I need to access it
very quickly for huge data sets.
For now, I was using NDBM, tying a hash with an indexed database. However,
this approach has drawbacks: large sizes of the index files,
platform-dependent index files, hard to store and retrieve additional
information etc. However, for someone like me it was a very easy and
straightforward approach.
I have now tested the sqlite which gives me the power of SQL. However, it
turned out to be roughly 100-500 times slower than NDBM, and the speed here
is of utter importance. First, a code snippet showing how I populated the
database:
my $dbh = DBI->connect('dbi:SQLite:dbname=blah.foo.sql','','');
$sth = $dbh->prepare( 'PRAGMA synchronous = OFF' ) ;
$sth->execute( ) ;
$sth = $dbh->prepare( 'create table t ( name TEXT, cont TEXT )' ) ;
$sth->execute( ) ;
$sth = $dbh->prepare( "insert into t ( name, cont ) values ( ?, ? )" ) ;
while( keys %records ) {
$sth->execute( $_, $records{$_} ) ;
}
And here is a code snippet showing how get the records:
my $dbh = DBI->connect('dbi:SQLite:dbname=blah.foo.sql','','');
my $sth = $dbh->prepare( "select * from t where name=?" ) ;
my $ntests = 10000 ; # number of tests
my $nrec = 700000 ; # number of records ;
# @keys hold all the keys, don't worry where I got it from
while( $ntests > 0 ) {
$i = int(rand($nrec)) ;
$key = $keys[ $i ] ;
# $t0 = [ gettimeofday ] ;
$sth->execute( $key ) ;
$all = $sth->fetchall_arrayref( ) ;
# $dt = tv_interval( $t0, [ gettimeofday ] ) ;
$ntests-- ;
}
Now, my questions are:
1) I don't know much about SQL or sqlite, maybe NDBM is expected to be so
much faster?
2) if not -- what do I do wrong? Should I ask in an SQL newsgroup for help
on optimizing my queries / database structure?
3) what other means could I use to speed up the access to these simple
records?
Best regards,
January
--
------------------------------
Date: Tue, 16 Oct 2007 07:44:25 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Question about simple databases in Perl
Message-Id: <1192545865.322894.304890@e9g2000prf.googlegroups.com>
On Oct 16, 10:30 am, January Weiner <january.wei...@gmail.com> wrote:
> while( keys %records ) {
> $sth->execute( $_, $records{$_} ) ;
> }
There's no way that works. It simply repeatedly tests to see if there
are any elements in the hash, and if so, executes that SQL. It does
not assign any elements to $_, and seeing as nothing in the block
changes %records, it's an infinite loop.
Paul Lalli
------------------------------
Date: 16 Oct 2007 17:44:54 GMT
From: xhoster@gmail.com
Subject: Re: Question about simple databases in Perl
Message-Id: <20071016134456.082$Cm@newsreader.com>
January Weiner <january.weiner@gmail.com> wrote:
> Hello,
>
> I have the following problem:
>
> I have a very simple relation keyword -- number. I need to access it
> very quickly for huge data sets.
>
> For now, I was using NDBM, tying a hash with an indexed database.
> However, this approach has drawbacks: large sizes of the index files,
> platform-dependent index files, hard to store and retrieve additional
> information etc. However, for someone like me it was a very easy and
> straightforward approach.
>
> I have now tested the sqlite which gives me the power of SQL. However,
> it turned out to be roughly 100-500 times slower than NDBM, and the speed
> here is of utter importance. First, a code snippet showing how I
> populated the database:
>
> my $dbh = DBI->connect('dbi:SQLite:dbname=blah.foo.sql','','');
> $sth = $dbh->prepare( 'PRAGMA synchronous = OFF' ) ;
> $sth->execute( ) ;
> $sth = $dbh->prepare( 'create table t ( name TEXT, cont TEXT )' ) ;
....
> my $sth = $dbh->prepare( "select * from t where name=?" ) ;
> Now, my questions are:
>
> 1) I don't know much about SQL or sqlite, maybe NDBM is expected to be so
> much faster?
> 2) if not -- what do I do wrong? Should I ask in an SQL newsgroup for
> help on optimizing my queries / database structure?
Other than the infinite loop mentions by someone else, you didn't build an
index on the "name" column or table "t". If you don't build an index,
then the program will have to scan the whole dataset to find what you
are looking for.
$dbh->do('create index asdfasdf on t(name)');
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Tue, 16 Oct 2007 14:24:38 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Setting perl's output buffer size
Message-Id: <mlqeu4-3e1.ln1@osiris.mauzo.dyndns.org>
Quoth Itay Greenspon <itay.gr@gmail.com>:
>
> When printing to an output handle, buffering varies with the type of
> output device.
> >From the perl cookbook:
> "Disk files are block buffered, often with a buffer size of more than
> 2K. Pipes and sockets are often buffered with a buffer size between
> 1/2 and 2K. Serial devices, including terminals, modems, mice, and
> joysticks, are normally line-buffered; stdio sends the entire line out
> only when it gets the newline."
>
>
> There's a simple mechanism to enable autoflushing (using $| or
> otherwise) ,
> But can one control the SIZE of the output buffer?
> (rather than setting buffering "on"/"off")
Why do you want to? The buffer is chosen to be an appropriate size to
get efficient IO.
With perls before 5.8, you can use IO::Handle::setvbuf to set the size
of stdio's buffers. After 5.8 perl doesn't use stdio by default, so the
size of the buffer cannot be set. If you have a need to control the
buffering that accurately, you are best off opening the file with a
:unix layer (see perldoc PerlIO) to get unbuffered IO, and doing the
buffering yourself.
Ben
------------------------------
Date: 16 Oct 2007 11:30:12 -0400
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: Strong Blog CGI in Perl
Message-Id: <87odezkrgb.fsf@mithril.chromatico.net>
>>>>> "I" == Izidoor <izidoor@invalid.com> writes:
I> So, I have to look deeper MovableType and Blosxom (and Er
I> maybe), but here is the list of feature I wish :
I> - Upload of text and image - Permalink - RSS feed - Archives
I> navigation - Searching - List of links toward articles
I> containing the most recent comments
I> And, without use of any external database could be a plus for
I> my case.
It sounds like you have some research to do. Alternately, you might
hire a good sysadmin, who can do the research for you, or a
consultant in this area, who will have done the research already.
You asked for "strong blog software in Perl," and I provided you with
three packages, two of which are extremely well-known in blogging.
(LiveJournal Server is, by the way, downloadable as open source.) If
you had additional requirements, you would have done well to ask about
them *first*, instead of telling the people who responded that their
answers didn't suit your needs.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Tue, 16 Oct 2007 18:11:50 +0200
From: Izidoor <izidoor@invalid.com>
Subject: Re: Strong Blog CGI in Perl
Message-Id: <MPG.217f01342a0f1c1e989969@news.tiscali.fr>
In article <87odezkrgb.fsf@mithril.chromatico.net>,
cwilbur@chromatico.net says...
> You asked for "strong blog software in Perl," and I provided you with
> three packages, two of which are extremely well-known in blogging.
> (LiveJournal Server is, by the way, downloadable as open source.) If
> you had additional requirements, you would have done well to ask about
> them *first*, instead of telling the people who responded that their
> answers didn't suit your needs.
>
I didn't said your response doens't suit my need. Blosxom seems to be
right for my need for example.
Also, why not, LiveJournal, but, really, I don't see where their
LiveJournal Server is downloadable from their site :
http://www.livejournal.com/site/. Do you have URL ?
Actually, I'm looking deeper in this list :
- MovableType
- Blosxom
- AngerWhale
- slashcode
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V11 Issue 941
**************************************