[29222] in Perl-Users-Digest
Perl-Users Digest, Issue: 466 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 29 16:09:54 2007
Date: Tue, 29 May 2007 13:09: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 Tue, 29 May 2007 Volume: 11 Number: 466
Today's topics:
Re: (Anno's) "Beyond Inside-Out" <bik.mido@tiscalinet.it>
Re: Beyond Inside-Out <rvtol+news@isolution.nl>
Re: Beyond Inside-Out anno4000@radom.zrz.tu-berlin.de
Cygwyn Question on broken link <ipellew@yahoo.com>
Does anyone have experience in how to handle signals in <needpassion@gmail.com>
Re: Does anyone have experience in how to handle signal xhoster@gmail.com
duplicates julia_2683@hotmail.com
Re: duplicates <mritty@gmail.com>
Re: duplicates usenet@DavidFilmer.com
Re: duplicates <jgibson@mail.arc.nasa.gov>
Re: FAQ 7.14 How can I pass/return a {Function, FileHan <brian.d.foy@gmail.com>
Re: find last match in a string? <bugbear@trim_papermule.co.uk_trim>
Re: find last match in a string? <bik.mido@tiscalinet.it>
Re: find last match in a string? xhoster@gmail.com
Re: find last match in a string? <abigail@abigail.be>
Re: find last match in a string? <someone@example.com>
Re: find last match in a string? <nobull67@gmail.com>
Re: find last match in a string? <xicheng@gmail.com>
Re: find last match in a string? <nobull67@gmail.com>
Re: find last match in a string? <bart.lateur@pandora.be>
Re: most active perl discussion forum <bart.lateur@pandora.be>
Re: PostgreSQL database access <justin.0704@purestblue.com>
Re: PostgreSQL database access <ts@dionic.net>
Re: PostgreSQL database access <kkeller-usenet@wombat.san-francisco.ca.us>
Re: PostgreSQL database access <justin.0704@purestblue.com>
Re: PostgreSQL database access <rvtol+news@isolution.nl>
vector graphics bindings, was Re: The Concepts and Conf <dot@dotat.at>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 29 May 2007 15:40:36 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: (Anno's) "Beyond Inside-Out"
Message-Id: <h9bo53ddo6u5t7qlkia2h9otsg5gkn2n0l@4ax.com>
On 29 May 2007 12:46:26 GMT, anno4000@radom.zrz.tu-berlin.de wrote:
>> Before he does so himself,
>
>I already did :)
Hadn't come out in my newsreader yet. I considered that enough! ;-)
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Tue, 29 May 2007 20:18:52 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Beyond Inside-Out
Message-Id: <f3i1vc.v8.1@news.isolution.nl>
anno4000@radom.zrz.tu-berlin.de schreef:
> Unlike inside-out classes, Alter-based classes don't need extra
> support for garbage collection and thread cloning. Like inside-
> out, they do need help in serialization. The standard modules
> Data::Dumper and Storable don't do anything for them.
"not anything" is too little, because both have hooks for integration
with classes.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 29 May 2007 18:45:43 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Beyond Inside-Out
Message-Id: <5c3amnF2te5gtU1@mid.dfncis.de>
Dr.Ruud <rvtol+news@isolution.nl> wrote in comp.lang.perl.misc:
> anno4000@radom.zrz.tu-berlin.de schreef:
>
> > Unlike inside-out classes, Alter-based classes don't need extra
> > support for garbage collection and thread cloning. Like inside-
> > out, they do need help in serialization. The standard modules
> > Data::Dumper and Storable don't do anything for them.
>
> "not anything" is too little, because both have hooks for integration
> with classes.
Oh yes, but the hooks must be supplied. If you give an inside-out
object to Data::Dumper, without help it will dump an undefined blessed
scalar: "bless( do{\(my $o = undef)}, 'SomeClass' )". The same goes
for Alter-based classes.
A difference is that with inside-out classes, essentially every class
must provide the hooks individually. Only the class knows which
object fields need to be dumped. With Alter-based classes, there is
the possibility of general methods to handle dumping, thawing and
freezing, that work with all objects and can be inherited or imported.
Anno
------------------------------
Date: 29 May 2007 10:28:58 -0700
From: ian <ipellew@yahoo.com>
Subject: Cygwyn Question on broken link
Message-Id: <1180459738.336318.290240@o5g2000hsb.googlegroups.com>
Hi;
I have broken the link on Cygwin /usr/lib/perl5/ that pointed to 5.8/
cygwin or whatever.
I have tried unistall and install but cannot get back to having the
cygwin dir in /usr/lib/perl5/5.8
Any suggestions pls
Regards
Ian
------------------------------
Date: 29 May 2007 11:27:18 -0700
From: mike <needpassion@gmail.com>
Subject: Does anyone have experience in how to handle signals in threaded program? Many thanks.
Message-Id: <1180463238.816448.24360@r19g2000prf.googlegroups.com>
Let's see sample1.pl first. In sample1.pl, there is no signal
capturing.
#!/usr/bin/perl
# sample1.pl
use threads;
$thr1 = new threads \&sample_sub, 1;
$thr2 = new threads \&sample_sub, 2;
print "pid = $$\n";
sub sample_sub {
my $SubNumber = shift @_;
while (1) {
print "$SubNumber run once...\n";
sleep(4);
}
}
$thr1->join;
$thr2->join;
sample1.pl exited immediately when it captured SIGUSR1.
Here is the output:
pid = 14094
1 run once...
2 run once...
1 run once...
2 run once...
User defined signal 1
It is easy to understand that the process just performed the default
signal response action and didn't care about the threads.
Let's see sample2.pl. It has signal capturing defined in the thread.
#!/usr/bin/perl
# sample2.pl
use threads;
$thr1 = new threads \&sample_sub, 1;
$thr2 = new threads \&sample_sub, 2;
print "pid = $$\n";
sub sample_sub {
my $SubNumber = shift @_;
$SIG{USR1}= sub { print "got signal.\n"; };
while (1) {
print "$SubNumber run once...\n";
sleep(4);
}
}
$thr1->join;
$thr2->join;
sample2.pl also exited immediately when it captured SIGUSR1, just as
not defined.
Here is the output:
pid = 14275
1 run once...
2 run once...
1 run once...
2 run once...
User defined signal 1
Question 1: Which thread captured the SIGUSR1? or just the process
captured the SIGUSR1?
Question 2: Why did the program NOT printing "got signal"? seems the
subroutine doesn't work.
In sample3.pl, I defined the signal capture outside of the thread.
#!/usr/bin/perl
# sample3.pl
use threads;
$SIG{USR1}= sub { print "got signal.\n"; };
$thr1 = new threads \&sample_sub, 1;
$thr2 = new threads \&sample_sub, 2;
print "pid = $$\n";
sub sample_sub {
my $SubNumber = shift @_;
while (1) {
print "$SubNumber run once...\n";
sleep(4);
}
}
$thr1->join;
$thr2->join;
When I sent SIGUSR1 to the process, no any actions were performed, and
I finally had to kill the process.
Question 3: Why did the program not capture the signal? seems the join
method is suspicious.
Let's see the last sample4.pl. I replaced the join method with detach,
and also made some other changes regarding the detach.
#!/usr/bin/perl
# sample4.pl
use threads;
my $exit;
$SIG{USR1}= sub { print "got signal.\n"; $exit++;};
$thr1 = new threads \&sample_sub, 1;
$thr2 = new threads \&sample_sub, 2;
print "pid = $$\n";
sub sample_sub {
my $SubNumber = shift @_;
while (1) {
print "$SubNumber run once...\n";
sleep(4);
}
}
$thr1->detach;
$thr2->detach;
while(!$exit) { sleep 1; }
When sample4.pl captured SIGUSR1, it acted just as I expected. Here is
the output:
pid = 14541
1 run once...
2 run once...
1 run once...
2 run once...
got signal.
A thread exited while 3 threads were running.
Quetion 4: What is the difference between join and detach when the
process/threads handle signal?
Quetion 5: Is it possible that the main process capture the signal and
then send the signal to all threads? How?
Quetion 6: I wanna code a program that has multiple threads, each
thread has its own task. Each thread is capable to capture specific
signal to perform specific job, for example, clean up and exit while
captured SIGUSR2. I wonder if any of you guys can write me a sample
code demonstrating how to capture signal in thread.
I will really appreciate your help, and many thanks for your patience
to read this posting.
------------------------------
Date: 29 May 2007 19:34:45 GMT
From: xhoster@gmail.com
Subject: Re: Does anyone have experience in how to handle signals in threaded program? Many thanks.
Message-Id: <20070529153448.070$xG@newsreader.com>
mike <needpassion@gmail.com> wrote:
> Let's see sample2.pl. It has signal capturing defined in the thread.
>
> #!/usr/bin/perl
> # sample2.pl
> use threads;
>
> $thr1 = new threads \&sample_sub, 1;
> $thr2 = new threads \&sample_sub, 2;
>
> print "pid = $$\n";
>
> sub sample_sub {
> my $SubNumber = shift @_;
>
> $SIG{USR1}= sub { print "got signal.\n"; };
>
> while (1) {
> print "$SubNumber run once...\n";
> sleep(4);
> }
> }
>
> $thr1->join;
> $thr2->join;
>
> sample2.pl also exited immediately when it captured SIGUSR1, just as
> not defined.
> Here is the output:
> pid = 14275
> 1 run once...
> 2 run once...
> 1 run once...
> 2 run once...
> User defined signal 1
>
> Question 1: Which thread captured the SIGUSR1?
The "main" thread, i.e. the one that was waiting on the join. Which
didn't have a sig handler in place.
> or just the process
> captured the SIGUSR1?
I don't understand how threading works under the hood, but in some respects
you can say that the main thread *is* the process.
> Question 2: Why did the program NOT printing "got signal"? seems the
> subroutine doesn't work.
Because the thread that got the signal did not have a sig handler in place.
> In sample3.pl, I defined the signal capture outside of the thread.
>
> #!/usr/bin/perl
> # sample3.pl
> use threads;
>
> $SIG{USR1}= sub { print "got signal.\n"; };
>
> $thr1 = new threads \&sample_sub, 1;
> $thr2 = new threads \&sample_sub, 2;
>
> print "pid = $$\n";
>
> sub sample_sub {
> my $SubNumber = shift @_;
>
> while (1) {
> print "$SubNumber run once...\n";
> sleep(4);
> }
> }
>
> $thr1->join;
> $thr2->join;
>
> When I sent SIGUSR1 to the process, no any actions were performed, and
> I finally had to kill the process.
>
> Question 3: Why did the program not capture the signal?
It did get the signal, at the "perl" level (the program written in C which
implements Perl). It just didn't do anything visible with it at the "Perl"
level (the level at which the typical programmer programs in Perl). If you
set the environment variable PERL_SIGNALS to "unsafe", you would probably
get the behavior you expected, unless you got a seg-fault instead.
> seems the join
> method is suspicious.
Under "safe" signals, the sig-handler is deferred until it is "safe" to
execute it. Apparently, this means until after the "join" completes.
Since the "join" never completes, the sig-handler is never run.
>
> Let's see the last sample4.pl. I replaced the join method with detach,
> and also made some other changes regarding the detach.
>
> #!/usr/bin/perl
> # sample4.pl
> use threads;
>
> my $exit;
> $SIG{USR1}= sub { print "got signal.\n"; $exit++;};
>
> $thr1 = new threads \&sample_sub, 1;
> $thr2 = new threads \&sample_sub, 2;
>
> print "pid = $$\n";
>
> sub sample_sub {
> my $SubNumber = shift @_;
>
> while (1) {
> print "$SubNumber run once...\n";
> sleep(4);
> }
> }
>
> $thr1->detach;
> $thr2->detach;
>
> while(!$exit) { sleep 1; }
>
> When sample4.pl captured SIGUSR1, it acted just as I expected. Here is
> the output:
>
> pid = 14541
> 1 run once...
> 2 run once...
> 1 run once...
> 2 run once...
> got signal.
> A thread exited while 3 threads were running.
>
> Quetion 4: What is the difference between join and detach when the
> process/threads handle signal?
It is not the difference between join and detach, it is the difference
between join and sleep.
> Quetion 5: Is it possible that the main process capture the signal and
> then send the signal to all threads? How?
> Quetion 6: I wanna code a program that has multiple threads, each
> thread has its own task. Each thread is capable to capture specific
> signal to perform specific job, for example, clean up and exit while
> captured SIGUSR2. I wonder if any of you guys can write me a sample
> code demonstrating how to capture signal in thread.
I wouldn't touch that with a ten foot pole. If need be, I'd use separate
processes, rather than threads.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 29 May 2007 10:33:53 -0700
From: julia_2683@hotmail.com
Subject: duplicates
Message-Id: <1180460033.481270.310610@o11g2000prd.googlegroups.com>
I would like to find and delete duplicates to reduce the number of
entries I have for each word. Need your help to achieve that.
Input
dog -> doggy
dog -> dogs
want -> wants
want -> wanting
want -> wanted
eat -> eaten
eat -> eating
eat -> eated
output
dog -> doggy dogs
want -> wants wanting wanted.
Thanks
------------------------------
Date: 29 May 2007 11:25:42 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: duplicates
Message-Id: <1180463142.085164.117380@k79g2000hse.googlegroups.com>
On May 29, 1:33 pm, julia_2...@hotmail.com wrote:
> I would like to find and delete duplicates to reduce the number of
> entries I have for each word. Need your help to achieve that.
> Input
> dog -> doggy
> dog -> dogs
> want -> wants
> want -> wanting
> want -> wanted
> eat -> eaten
> eat -> eating
> eat -> eated
> output
> dog -> doggy dogs
> want -> wants wanting wanted.
What have you tried so far? How did it not meet your expectations?
>From where does this data come, and in what structure do you have it
stored? Have you searched the FAQ?
$ perldoc -q duplicate
Found in /opt2/Perl5_8_4/lib/perl5/5.8.4/pod/perlfaq4.pod
How can I remove duplicate elements from a list or array?
Paul Lalli
------------------------------
Date: 29 May 2007 11:28:15 -0700
From: usenet@DavidFilmer.com
Subject: Re: duplicates
Message-Id: <1180463295.223830.293390@g37g2000prf.googlegroups.com>
On May 29, 10:33 am, julia_2...@hotmail.com wrote:
> I would like to find and delete duplicates to reduce the number of
> entries I have for each word. Need your help to achieve that.
How about this:
#!/usr/bin/perl
use strict;
use warnings;
my %word;
while (<DATA>) {
chomp;
my ($word1, $word2) = split (/ -> /, $_);
push @{$word{$word1}}, $word2;
}
print($_," -> ",join(" ",@{$word{$_}}),"\n") for keys %word;
__DATA__
dog -> doggy
dog -> dogs
want -> wants
want -> wanting
want -> wanted
eat -> eaten
eat -> eating
eat -> eated
OUTPUT
eat -> eaten eating eated
want -> wants wanting wanted
dog -> doggy dogs
>> eat -> eated
eated???
--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)
------------------------------
Date: Tue, 29 May 2007 11:38:42 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: duplicates
Message-Id: <290520071138426890%jgibson@mail.arc.nasa.gov>
In article <1180460033.481270.310610@o11g2000prd.googlegroups.com>,
<julia_2683@hotmail.com> wrote:
> I would like to find and delete duplicates to reduce the number of
> entries I have for each word. Need your help to achieve that.
> Input
> dog -> doggy
> dog -> dogs
> want -> wants
> want -> wanting
> want -> wanted
> eat -> eaten
> eat -> eating
> eat -> eated
> output
> dog -> doggy dogs
> want -> wants wanting wanted.
Here's a fish:
#!/usr/local/bin/perl
#
use warnings;
use strict;
my %hash;
while(<DATA>) {
chomp;
my($key,$val) = split(/\s*->\s*/);
push(@{$hash{$key}},$val);
}
for my $key (sort keys %hash) {
print "$key -> @{$hash{$key}}\n";
}
__DATA__
dog -> doggy
dog -> dogs
want -> wants
want -> wanting
want -> wanted
eat -> eaten
eat -> eating
eat -> eated
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
------------------------------
Date: Tue, 29 May 2007 13:00:24 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 7.14 How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regex}?
Message-Id: <290520071300240570%brian.d.foy@gmail.com>
In article <f3glip$tl2$1@usenet01.boi.hp.com>, Brian Helterlilne
<brian.helterline@hp.com> wrote:
> PerlFAQ Server wrote:
> > sub func {
> > my $passed_fh = shift;
> >
> > my $line = <$fh>;
> ^^^^
> while this will work as written, isn't the point to use $passed_fh?
fixed, thanks,
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: Tue, 29 May 2007 14:29:23 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: find last match in a string?
Message-Id: <465c2ab3$0$8726$ed2619ec@ptn-nntp-reader02.plus.net>
Gunnar Hjalmarsson wrote:
> bugbear wrote:
>> Gunnar Hjalmarsson wrote:
>>> bugbear wrote:
>>>>
>>>> my $a = "abcabd";
>>>> $a =~ m/(ab.)/;
>>>> print "$1\n";
>>>>
>>>> I'd like (somehow) to get "abd" printed, not "abc"
>>>> which is what the above code (obviously) does.
>>>
>>> $a =~ /.*(ab.)/s;
>>
>> Are there any performance or memory issues
>> with this approach if $a is rather large?
>
> Not that I'm aware of.
>
> Btw, how large is "rather large"?
No probs - in my actual usage, a coupla' K,
but I was thinking more generally, since the regexp
would essentially be matching the majority
of the input (assuming my "real" target
is near the end)
BugBear
------------------------------
Date: Tue, 29 May 2007 15:38:46 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: find last match in a string?
Message-Id: <m0bo53hcbj1nsk6osdovp5p09c3ecvs0ic@4ax.com>
On Tue, 29 May 2007 13:05:18 +0100, bugbear
<bugbear@trim_papermule.co.uk_trim> wrote:
>> $a =~ /.*(ab.)/s;
>
>Are there any performance or memory issues
>with this approach if $a is rather large?
Yes, terrible ones. I would start worrying as soon as possible. Fire
up Benchmark.pm and start micro-optimizing.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 29 May 2007 15:23:38 GMT
From: xhoster@gmail.com
Subject: Re: find last match in a string?
Message-Id: <20070529112340.002$Gx@newsreader.com>
bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
> Gunnar Hjalmarsson wrote:
> > bugbear wrote:
> >> Normally, perl searches left-to-right, and
> >> (consequently) will normally give me
> >> the first match for a regexp in a string.
> >>
> >> Is there anyway to get the LAST match?
> >>
> >> e.g.
> >>
> >> my $a = "abcabd";
> >> $a =~ m/(ab.)/;
> >> print "$1\n";
> >>
> >> I'd like (somehow) to get "abd" printed, not "abc"
> >> which is what the above code (obviously) does.
> >
> > $a =~ /.*(ab.)/s;
>
> Are there any performance or memory issues
> with this approach if $a is rather large?
Not particularly, other than the ones associated with $a being large
in the first place.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 29 May 2007 15:33:43 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: find last match in a string?
Message-Id: <slrnf5oht7.ag0.abigail@alexandra.abigail.be>
bugbear (bugbear@trim_papermule.co.uk_trim) wrote on M September MCMXCIII
in <URL:news:465c16ff$0$8715$ed2619ec@ptn-nntp-reader02.plus.net>:
)) Gunnar Hjalmarsson wrote:
)) > bugbear wrote:
)) >> Normally, perl searches left-to-right, and
)) >> (consequently) will normally give me
)) >> the first match for a regexp in a string.
)) >>
)) >> Is there anyway to get the LAST match?
)) >>
)) >> e.g.
)) >>
)) >> my $a = "abcabd";
)) >> $a =~ m/(ab.)/;
)) >> print "$1\n";
)) >>
)) >> I'd like (somehow) to get "abd" printed, not "abc"
)) >> which is what the above code (obviously) does.
)) >
)) > $a =~ /.*(ab.)/s;
))
)) Are there any performance or memory issues
)) with this approach if $a is rather large?
Of course.
It's the same as if you enter a large hallway of say a castle.
Getting to the *last* room will take longer then getting to
the *first* room.
Abigail
--
perl -wle 'eval {die [[qq [Just another Perl Hacker]]]};; print
${${${@}}[$#{@{${@}}}]}[$#{${@{${@}}}[$#{@{${@}}}]}]'
------------------------------
Date: Tue, 29 May 2007 16:33:39 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: find last match in a string?
Message-Id: <DBY6i.60653$g63.43224@edtnps82>
bugbear wrote:
> Normally, perl searches left-to-right, and
> (consequently) will normally give me
> the first match for a regexp in a string.
>
> Is there anyway to get the LAST match?
>
> e.g.
>
> my $a = "abcabd";
> $a =~ m/(ab.)/;
> print "$1\n";
>
> I'd like (somehow) to get "abd" printed, not "abc"
> which is what the above code (obviously) does.
$ perl -le'
my $string = reverse "abcabd";
my $pattern = reverse "ab.";
print scalar reverse $1 if $string =~ /($pattern)/;
'
abd
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
------------------------------
Date: 29 May 2007 10:35:29 -0700
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: find last match in a string?
Message-Id: <1180460129.316617.97760@g4g2000hsf.googlegroups.com>
On May 29, 2:29 pm, bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
> Gunnar Hjalmarsson wrote:
> > bugbear wrote:
> >> Gunnar Hjalmarsson wrote:
> >>> bugbear wrote:
>
> >>>> my $a = "abcabd";
> >>>> $a =~ m/(ab.)/;
> >>>> print "$1\n";
>
> >>>> I'd like (somehow) to get "abd" printed, not "abc"
> >>>> which is what the above code (obviously) does.
>
> >>> $a =~ /.*(ab.)/s;
>
> >> Are there any performance or memory issues
> >> with this approach if $a is rather large?
>
> > Not that I'm aware of.
>
> > Btw, how large is "rather large"?
>
> No probs - in my actual usage, a coupla' K,
> but I was thinking more generally, since the regexp
> would essentially be matching the majority
> of the input (assuming my "real" target
> is near the end)
If the data is large, speed is of the essence and the target is a
literal string then use rindex(). It is one $EXPLETIVE of a lot
faster!
Do not let personalities[1] put you off using an index()/rindex()/
substr() approach rather than a regex approach.
If ease of coding is more important then speed use the pattern match.
Note, there's no big memory issue with the regex as the pattern is not
capturing the .* bit.
use strict;
use warnings;
use Benchmark;
my $a="sadihdiasjdisajdisadisadjsiadjisadjisadjsadabzaaa" x 10_000;
timethese 10_000, {
match => sub {
my ($q) = $a =~ /.*(ab.)/;
},
rindex => sub {
my $i = rindex $a,'ab';
my $q = $i == -1 ? undef : substr($a,$i,3);
}
};
__END__
Benchmark: timing 10000 iterations of match, rindex...
match: 21 wallclock secs (15.96 usr + 0.17 sys = 16.13 CPU) @
619.85/s (n=10000)
rindex: 0 wallclock secs ( 0.01 usr + 0.00 sys = 0.01 CPU) @
1000000.00/s (n=10000)
(warning: too few iterations for a reliable count)
[1] In particular a certain "personality" who recommends index()/
rindex()/substr() for _all_ problems that would usually be solved with
a simple regex.
------------------------------
Date: 29 May 2007 10:52:55 -0700
From: Xicheng Jia <xicheng@gmail.com>
Subject: Re: find last match in a string?
Message-Id: <1180461174.922066.219000@j4g2000prf.googlegroups.com>
On May 29, 1:35 pm, Brian McCauley <nobul...@gmail.com> wrote:
> On May 29, 2:29 pm, bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
>
>
>
> > Gunnar Hjalmarsson wrote:
> > > bugbear wrote:
> > >> Gunnar Hjalmarsson wrote:
> > >>> bugbear wrote:
>
> > >>>> my $a = "abcabd";
> > >>>> $a =~ m/(ab.)/;
> > >>>> print "$1\n";
>
> > >>>> I'd like (somehow) to get "abd" printed, not "abc"
> > >>>> which is what the above code (obviously) does.
>
> > >>> $a =~ /.*(ab.)/s;
>
> > >> Are there any performance or memory issues
> > >> with this approach if $a is rather large?
>
> > > Not that I'm aware of.
>
> > > Btw, how large is "rather large"?
>
> > No probs - in my actual usage, a coupla' K,
> > but I was thinking more generally, since the regexp
> > would essentially be matching the majority
> > of the input (assuming my "real" target
> > is near the end)
>
> If the data is large, speed is of the essence and the target is a
> literal string then use rindex(). It is one $EXPLETIVE of a lot
> faster!
>
> Do not let personalities[1] put you off using an index()/rindex()/
> substr() approach rather than a regex approach.
>
> If ease of coding is more important then speed use the pattern match.
>
> Note, there's no big memory issue with the regex as the pattern is not
> capturing the .* bit.
>
> use strict;
> use warnings;
> use Benchmark;
> my $a="sadihdiasjdisajdisadisadjsiadjisadjisadjsadabzaaa" x 10_000;
> timethese 10_000, {
> match => sub {
> my ($q) = $a =~ /.*(ab.)/;
> },
> rindex => sub {
> my $i = rindex $a,'ab';
> my $q = $i == -1 ? undef : substr($a,$i,3);
> }};
>
what if
$a = "abzab";
you need to fix this first...
Regards,
Xicheng
------------------------------
Date: 29 May 2007 11:12:59 -0700
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: find last match in a string?
Message-Id: <1180462379.548614.113240@q69g2000hsb.googlegroups.com>
On May 29, 6:52 pm, Xicheng Jia <xich...@gmail.com> wrote:
> On May 29, 1:35 pm, Brian McCauley <nobul...@gmail.com> wrote:
> > On May 29, 2:29 pm, bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
>
> > > Gunnar Hjalmarsson wrote:
> > > > bugbear wrote:
> > > >> Gunnar Hjalmarsson wrote:
> > > >>> bugbear wrote:
>
> > > >>>> my $a = "abcabd";
> > > >>>> $a =~ m/(ab.)/;
> > > >>>> print "$1\n";
>
> > > >>>> I'd like (somehow) to get "abd" printed, not "abc"
> > > >>>> which is what the above code (obviously) does.
>
> > > >>> $a =~ /.*(ab.)/s;
>
> > If the data is large, speed is of the essence and the target is a
> > literal string then use rindex(). It is one $EXPLETIVE of a lot
> > faster!
>
> > my $i = rindex $a,'ab';
> > my $q = $i == -1 ? undef : substr($a,$i,3);
>
> what if
>
> $a = "abzab";
>
> you need to fix this first...
It would be more accurate to say you need to _consider_ this.
Although the rindex() solution does not exactly match the regex
solution it is very likely that in the OP's real situation this is a
non-issue so there's nothing to fix.
------------------------------
Date: Tue, 29 May 2007 19:58:44 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: find last match in a string?
Message-Id: <v71p53pup8h5d0os7u0hdfrjo6vl42p4ei@4ax.com>
bugbear wrote:
>Gunnar Hjalmarsson wrote:
>> bugbear wrote:
>>> Gunnar Hjalmarsson wrote:
>>>> bugbear wrote:
>>>>> I'd like (somehow) to get "abd" printed, not "abc"
>>>>> which is what the above code (obviously) does.
>>>>
>>>> $a =~ /.*(ab.)/s;
>>>
>>> Are there any performance or memory issues
>>> with this approach if $a is rather large?
>>
>> Not that I'm aware of.
>>
>> Btw, how large is "rather large"?
>
>No probs - in my actual usage, a coupla' K,
>but I was thinking more generally, since the regexp
>would essentially be matching the majority
>of the input (assuming my "real" target
>is near the end)
Good point. Once your string gets big, you might reconsider to use the
pattern of "sexeger", which is just the reverse of "regexes", i.e.
regexes from the back.
See the post on Perlmonks:
http://perlmonks.org/?node_id=33410
You (likely still) have to reverse the regex by hand, and you may have
to test to see if it's worth the trouble.
--
Bart.
------------------------------
Date: Tue, 29 May 2007 18:35:30 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: most active perl discussion forum
Message-Id: <rfso5390od2u15j9dukk4vhoi5debm1330@4ax.com>
Gunnar Hjalmarsson wrote:
>Greg Benjamin wrote:
>> This newsgroup only has a few posts per day.
>
>While that may be true the past week, clpmisc is usually a high traffic
>newsgroup.
It's slow compared to what it was aroundn 2000, when it got 300 messages
a day. Now the average floats areound 50/day.
>> where is the liveliest perl talk these days?
>
>It's here. Among other places.
Perlmonks (http://perlmonks.org) is a web based forum, and I've been
told Perl related IRC chat activity is very high these days, though I
don't use it myself.
--
Bart.
------------------------------
Date: Tue, 29 May 2007 13:43:44 -0000
From: Justin C <justin.0704@purestblue.com>
Subject: Re: PostgreSQL database access
Message-Id: <slrnf5obgg.r8f.justin.0704@stigmata.purestblue.com>
On 2007-05-29, Paul Lalli <mritty@gmail.com> wrote:
> On May 29, 8:37 am, Justin C <justin.0...@purestblue.com> wrote:
>> I've a PostgreSQL database that I need to interact with using perl. I
>> need to be able to add records and amend records only. I'm trying to
>> find where to start.
>
> http://dbi.perl.org
> http://search.cpan.org/~timb/DBI-1.56/DBI.pm
> http://search.cpan.org/~dbdpg/DBD-Pg-1.49/Pg.pm
Thank you Paul, and Tim. I've already got the DBI bit (I kinda guessed
I'd need it). The DBD::Pg is what I'm missing.
Justin.
--
Justin C, by the sea.
------------------------------
Date: Tue, 29 May 2007 15:30:03 +0100
From: Tim Southerwood <ts@dionic.net>
Subject: Re: PostgreSQL database access
Message-Id: <465c38eb$0$643$5a6aecb4@news.aaisp.net.uk>
Justin C wrote:
> I've a PostgreSQL database that I need to interact with using perl. I
> need to be able to add records and amend records only. I'm trying to
> find where to start. Searching CPAN for PostgreSQL returns a large list
> of modules, I've been through a lot of pages and nothing stands out as
> being the/a module that I need. Is there a good reference anywhere, in
> simple terms (I've no experience *at all* with databases - but I do have
> a book!), that'll tell me which module(s) I need?
Oh, for the "howto":
perldoc DBI
and look at the SYNOPSIS.
I think you mostly need:
$rv = $dbh->do($statement, \%attr, @bind_values);
(or perhaps prepare and execute, but do() will do for starters).
Hint - use bindvars, it will save infinite grief with quoting
perldoc DBD::Pg will give you the magic for setting up a Postgresql DSN.
Another hint: setting RaiseError is a good idea - anything goes wrong and it
will blow up your code, even without explicit error checks, which is
usually a GOOD THING (TM) unless you really want to handle failures nicely.
HTH
Tim
------------------------------
Date: Tue, 29 May 2007 10:33:57 -0700
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: PostgreSQL database access
Message-Id: <6p4ui4xcu5.ln2@goaway.wombat.san-francisco.ca.us>
On 2007-05-29, Justin C <justin.0704@purestblue.com> wrote:
> I've a PostgreSQL database that I need to interact with using perl. I
> need to be able to add records and amend records only.
You've already gotten the Perl-relevant parts of your answer; I'll just
add that restricting access to add or update is a function of the db, so
you should read the PostgreSQL documention at their website for these
tasks.
--keith
--
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information
------------------------------
Date: Tue, 29 May 2007 18:59:42 -0000
From: Justin C <justin.0704@purestblue.com>
Subject: Re: PostgreSQL database access
Message-Id: <slrnf5ou16.5pi.justin.0704@satori.local>
In article <465c38eb$0$643$5a6aecb4@news.aaisp.net.uk>, Tim Southerwood wrote:
>
> Oh, for the "howto":
>
> perldoc DBI
>
> and look at the SYNOPSIS.
>
> I think you mostly need:
[snip]
Thanks, noted.
Justin.
--
Justin C, by the sea.
------------------------------
Date: Tue, 29 May 2007 21:50:01 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: PostgreSQL database access
Message-Id: <f3i7kj.148.1@news.isolution.nl>
Justin C schreef:
> I've a PostgreSQL database that I need to interact with using perl.
> I need to be able to add records and amend records only.
Consider DBIx::Simple
http://search.cpan.org/perldoc?DBIx::Simple
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 29 May 2007 14:27:02 +0100 (BST)
From: Tony Finch <dot@dotat.at>
Subject: vector graphics bindings, was Re: The Concepts and Confusions of Prefix, Infix, Postfix and Fully Functional Notations
Message-Id: <2uc*jQWLr@news.chiark.greenend.org.uk>
Jon Harrop <jon@ffconsultancy.com> wrote:
>
>Anyway, are there any libraries to do hardware accelerated vector graphics
>in Perl, Python, Lisp, Java or any functional language (except OCaml and F#
>and excluding WPF and Silverlight)?
http://www.cairographics.org/bindings/
That covers all the languages you named, plus O'Caml and Haskell.
Tony.
--
f.a.n.finch <dot@dotat.at> http://dotat.at/
GERMAN BIGHT: NORTH BECOMING CYCLONIC 4 OR 5, THEN WEST 5 OR 6. MODERATE OR
ROUGH. RAIN OR DRIZZLE. MODERATE OR GOOD, OCCASIONALLY POOR.
------------------------------
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 466
**************************************