[29559] in Perl-Users-Digest
Perl-Users Digest, Issue: 803 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 28 16:09:40 2007
Date: Tue, 28 Aug 2007 13:09:07 -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, 28 Aug 2007 Volume: 11 Number: 803
Today's topics:
Re: comparing two arrays in perl <jkstill@gmail.com>
Re: comparing two arrays in perl <jkstill@gmail.com>
Re: FAQ 8.42 How do I make a system() exit on control-C <tkriel@gmail.com>
File locking (Not Flock) <bill@ts1000.us>
Re: File locking (Not Flock) <simon.chao@fmr.com>
Re: fork off several children processes xhoster@gmail.com
Re: fork off several children processes <rsarpi@gmail.com>
Re: great and better hash eval <bik.mido@tiscalinet.it>
Re: great and better hash eval anno4000@radom.zrz.tu-berlin.de
Re: great and better hash eval <bik.mido@tiscalinet.it>
How to do pattern matching for multiple files in Perl <shafa.fahad@gmail.com>
Re: How to do pattern matching for multiple files in Pe <ben@morrow.me.uk>
Re: How to make this case insenstive <uri@stemsystems.com>
mod_perl: can't locate object method... markus.rietzler@rzf.fin-nrw.de
mod_perl: can't locate object method... markus.rietzler@rzf.fin-nrw.de
mod_perl: markus.rietzler@rzf.fin-nrw.de
Re: Most Appropriate Data Structure/Method <jkstill@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 28 Aug 2007 18:34:23 -0000
From: jkstill <jkstill@gmail.com>
Subject: Re: comparing two arrays in perl
Message-Id: <1188326063.088562.234350@x35g2000prf.googlegroups.com>
On Aug 27, 11:17 am, bcdixit <bhooshan.di...@gmail.com> wrote:
> Hi,
> I have two arrays, for example,
>
> @array = ("john","larry","kevin","peter","mike")
> @exclude = ("john","kevin")
>
> i want to delete from @array , values that exist in @exclude.
> i.e. i want my @array to look like
>
> @array("","larry","","peter","mike")
>
> i have written this code but it doesnot seem to work.
>
> foreach$i(0..$#exclude)
> {
> foreach$x(0..$#array)
> {
> if($array[$x] eq $exclude[$i])
> {
> delete($array[$x]);
> next;
> }
> }
> }
>
> am I missing something? is there someother better way to do it in
> perl?
>
> thanks
> -bd
This looks promising:
http://www.perlmonks.org/index.pl?node=429761
------------------------------
Date: Tue, 28 Aug 2007 19:12:14 -0000
From: jkstill <jkstill@gmail.com>
Subject: Re: comparing two arrays in perl
Message-Id: <1188328334.533852.5570@q4g2000prc.googlegroups.com>
On Aug 28, 11:34 am, jkstill <jkst...@gmail.com> wrote:
> On Aug 27, 11:17 am, bcdixit <bhooshan.di...@gmail.com> wrote:
>
>
>
> > Hi,
> > I have two arrays, for example,
>
> > @array = ("john","larry","kevin","peter","mike")
> > @exclude = ("john","kevin")
>
> > i want to delete from @array , values that exist in @exclude.
> > i.e. i want my @array to look like
>
> > @array("","larry","","peter","mike")
>
> > i have written this code but it doesnot seem to work.
>
> > foreach$i(0..$#exclude)
> > {
> > foreach$x(0..$#array)
> > {
> > if($array[$x] eq $exclude[$i])
> > {
> > delete($array[$x]);
> > next;
> > }
> > }
> > }
>
> > am I missing something? is there someother better way to do it in
> > perl?
>
> > thanks
> > -bd
>
> This looks promising:
>
> http://www.perlmonks.org/index.pl?node=429761
My bad, replied to the wrong thread.
------------------------------
Date: Tue, 28 Aug 2007 19:11:08 -0000
From: tk <tkriel@gmail.com>
Subject: Re: FAQ 8.42 How do I make a system() exit on control-C?
Message-Id: <1188328268.556963.61700@57g2000hsv.googlegroups.com>
On Aug 27, 3:03 pm, PerlFAQ Server <br...@stonehenge.com> wrote:
> This is an excerpt from the latest version perlfaq8.pod, which
> comes with the standard Perl distribution. These postings aim to
> reduce the number of repeated questions as well as allow the community
> to review and update the answers. The latest version of the complete
> perlfaq is athttp://faq.perl.org.
>
> --------------------------------------------------------------------
>
> 8.42: How do I make a system() exit on control-C?
>
> You can't. You need to imitate the system() call (see perlipc for sample
> code) and then have a signal handler for the INT signal that passes the
> signal on to the subprocess. Or you can check for it:
>
> $rc = system($cmd);
> if ($rc & 127) { die "signal death" }
>
> --------------------------------------------------------------------
>
> The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
> are not necessarily experts in every domain where Perl might show up,
> so please include as much information as possible and relevant in any
> corrections. The perlfaq-workers also don't have access to every
> operating system or platform, so please include relevant details for
> corrections to examples that do not work on particular platforms.
> Working code is greatly appreciated.
>
> If you'd like to help maintain the perlfaq, see the details in
> perlfaq.pod.
>
> --
> Posted via a free Usenet account fromhttp://www.teranews.com
Instead of using system($cmd); use $answ = `$cmd` .....You can
Control-C out of that.
------------------------------
Date: Tue, 28 Aug 2007 11:39:59 -0700
From: Bill H <bill@ts1000.us>
Subject: File locking (Not Flock)
Message-Id: <1188326399.099166.277650@w3g2000hsg.googlegroups.com>
Is there a perl / linux way of locking a file? Not the FLOCK method
when you open a file, but setting the actual file as read only, or
read / write?
Bill H
------------------------------
Date: Tue, 28 Aug 2007 18:48:05 -0000
From: it_says_BALLS_on_your forehead <simon.chao@fmr.com>
Subject: Re: File locking (Not Flock)
Message-Id: <1188326885.980254.224360@22g2000hsm.googlegroups.com>
On Aug 28, 2:39 pm, Bill H <b...@ts1000.us> wrote:
> Is there a perl / linux way of locking a file? Not the FLOCK method
> when you open a file, but setting the actual file as read only, or
> read / write?
my $cnt = chmod 0755, 'foo', 'bar';
------------------------------
Date: 28 Aug 2007 16:05:38 GMT
From: xhoster@gmail.com
Subject: Re: fork off several children processes
Message-Id: <20070828120539.875$FU@newsreader.com>
monk <rsarpi@gmail.com> wrote:
> > > What I want is to have something like all parentX() subroutines
> > > executing along with all childrenX() subroutines, all in parallel,
> > > all together like a good family.
> >
> > I don't understand what you want. It sounds like you want to make
> > all the processes siblings. If that is the case, why do you name
> > some of them parents and some of them children?
>
> Thanks for your reply.
>
> So should I have only *one* subroutine under the parent section,
> and the rest of the subroutines under the child section?
>
> Would that accomplish the goal of running several children in
> parallel?
If you want to run N processes in parallel, you need to have N-1 forks.
(or N forks if the "parent" does nothing of its own other than fork
and wait, which is not a bad idea). See, for example,
Parallel::ForkManager.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Tue, 28 Aug 2007 19:57:59 -0000
From: monk <rsarpi@gmail.com>
Subject: Re: fork off several children processes
Message-Id: <1188331079.768874.238490@m37g2000prh.googlegroups.com>
Thanks all, for what I need I'll use Parallel::ForkManager.
That was right on the money.
;*)
------------------------------
Date: Tue, 28 Aug 2007 13:08:49 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: great and better hash eval
Message-Id: <nh08d39hliunoum4oupt5ap2h8ung74lh5@4ax.com>
On Mon, 27 Aug 2007 12:00:32 +0200, john swilting
<john.swilting@wanadoo.fr> wrote:
>> http://en.wikipedia.org/wiki/Darmok
>>
>>
>> Michele
>tirare la maniglia e arribaltare il copperchio
:)
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: 28 Aug 2007 14:42:32 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: great and better hash eval
Message-Id: <5jiqioF3u7rvhU1@mid.dfncis.de>
Michele Dondi <bik.mido@tiscalinet.it> wrote in comp.lang.perl.misc:
> On Mon, 27 Aug 2007 12:00:32 +0200, john swilting
> <john.swilting@wanadoo.fr> wrote:
>
> >> http://en.wikipedia.org/wiki/Darmok
> >>
> >>
> >> Michele
> >tirare la maniglia e arribaltare il copperchio
Pull the handle and lift the lid?
Anno
------------------------------
Date: Tue, 28 Aug 2007 19:46:08 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: great and better hash eval
Message-Id: <fhn8d31naafokma40619flbrqu55ol4i09@4ax.com>
On 28 Aug 2007 14:42:32 GMT, anno4000@radom.zrz.tu-berlin.de wrote:
>> >tirare la maniglia e arribaltare il copperchio
>
>Pull the handle and lift the lid?
Yep, except that the verb "arribaltare" does not exist, but may sound
like a dialectal form of "ribaltare" and "copperchio" should be
written with one "p". Oh, and although the whole phrase is
syntactically correct in Italian, it also sounds somewhat strange with
the verbs at infinitive. But I understood it in the sense of: throw
this into the water closet and flush. All in all, if I got it right,
the most comprehensible of the OP's posts thus far. (Hence the
original reference to Darmok.)
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, 28 Aug 2007 13:23:36 -0000
From: Kimi <shafa.fahad@gmail.com>
Subject: How to do pattern matching for multiple files in Perl
Message-Id: <1188307416.781467.288380@d55g2000hsg.googlegroups.com>
Hi,
I am new to Perl and know ksh better. He is what I am doing with ksh
"$ cat file_list
file1.log
file2.log
$cat file_list | xargs -L 500 egrep -ci "pattern_to_search" /dev/null
| grep -v "0$" | sort -b -t ":" -k4,4 -T "/tmp" > "summary_file"
$ cat summary_file
file1.log:2
file2.log:2
$cat file_list | xargs -L 500 egrep -A3 -i "pattern_to_search" | cut -
c1-1024 > "detail_file"
$cat detail_file
file1.log: pattern_to_search 1
file1.log: pattern_to_search 2
file2.log: pattern_to_search 6
file2.log: pattern_to_search 7"
inside the ksh script, pattern.ksh
------------------------------------------------
cat file_list | xargs -L 500 egrep -ci "pattern_to_search" /dev/null |
grep -v "0$" | sort -b -t ":" -k4,4 -T "/tmp" > "summary_file"
cat file_list | xargs -L 500 egrep -A3 -i "pattern_to_search" | cut -
c1-1024 > "detail_file"
And I was told that perl is faster than ksh. If so, how can we do the
above operation using perl. I dont think using the above statement
directly inside perl script as
`cat file_list | xargs -L 500 egrep -ci "pattern_to_search" /dev/null
| grep -v "0$" | sort -b -t ":" -k4,4 -T "/tmp" > "summary_file"`
`cat file_list | xargs -L 500 egrep -A3 -i "pattern_to_search" | cut -
c1-1024 > "detail_file"`
is the right way. Any suggestions and pointers is appreciable.
Thanks in Advance,
Kimi
------------------------------
Date: Tue, 28 Aug 2007 15:55:11 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How to do pattern matching for multiple files in Perl
Message-Id: <fjpdq4-19b.ln1@osiris.mauzo.dyndns.org>
Quoth Kimi <shafa.fahad@gmail.com>:
> Hi,
>
> I am new to Perl and know ksh better. He is what I am doing with ksh
>
<snip>
> cat file_list | xargs -L 500 egrep -ci "pattern_to_search" /dev/null |
> grep -v "0$" | sort -b -t ":" -k4,4 -T "/tmp" > "summary_file"
> cat file_list | xargs -L 500 egrep -A3 -i "pattern_to_search" | cut -
> c1-1024 > "detail_file"
>
> And I was told that perl is faster than ksh. If so, how can we do the
> above operation using perl. I dont think using the above statement
> directly inside perl script as
>
> `cat file_list | xargs -L 500 egrep -ci "pattern_to_search" /dev/null
> | grep -v "0$" | sort -b -t ":" -k4,4 -T "/tmp" > "summary_file"`
> `cat file_list | xargs -L 500 egrep -A3 -i "pattern_to_search" | cut -
> c1-1024 > "detail_file"`
>
> is the right way. Any suggestions and pointers is appreciable.
You can open a file with open, see perldoc -f open.
You can read its contents with the <> operator, see perldoc perlop.
You can filter a list with the grep function, see perldoc -f grep, and
perldoc perlretut.
You can sort a list with the sort function, see perldoc -f sort.
You can extract a piece of a string with the substr function, see
perldoc -f substr.
If you have tried to put these pieces together and can't make it work,
post what you have and we'll help you fix it.
Ben
--
Razors pain you / Rivers are damp
Acids stain you / And drugs cause cramp. [Dorothy Parker]
Guns aren't lawful / Nooses give
Gas smells awful / You might as well live. ben@morrow.me.uk
------------------------------
Date: Tue, 28 Aug 2007 14:57:19 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: How to make this case insenstive
Message-Id: <x7d4x7906n.fsf@mail.sysarch.com>
>>>>> "R" == Ruud <rvtol+news@isolution.nl> writes:
R> it_says_BALLS_on_your forehead schreef:
>> Daniel:
>>> I am checking to see if the name is the same name as in $row[1] but
>>> should be case insensitive.
>>>
>>> my $line = DBI::neat_list(\@row, 70, ',');
>>> if ($name ne $row[1])
>>> do
>>> error message
>>
>> an alternative to the lc() or uc() solution is to use a regex
>> (although this is probably less efficient).
>>
>> if ( $name =~ m/$row[1]/i ) {
>> do {
>> blah
R> Missing: quotemeta.
also missing regex anchors which are needed since he did 'ne'.
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, 28 Aug 2007 05:09:33 -0700
From: markus.rietzler@rzf.fin-nrw.de
Subject: mod_perl: can't locate object method...
Message-Id: <1188302973.987158.237590@o80g2000hse.googlegroups.com>
hi group,
i have the following problem: two servers, identically setup - at
least i used the same files and when comparing everything (almost all)
looks identical. both are configured with apche 2.0.x, mod_perl2.
on both servers a mod_perl modul is configured in httpd.conf. but when
running on the new server i've installed i get
Can't locate object method "dir_config" via package
"Apache2::RequestRec" at /opt/perl5/lib/site_perl/5.8.7/foo/
redirect.pm line 21.
this is the beginning of the modul:
package foo::redirect;
use Apache2::Const qw(:common HTTP_MOVED_TEMPORARILY);
use Apache2::Log ();
use Apache2::URI ();
use Apache2::Connection();
use Apache2::Request;
use Apache2::SubRequest();
use Digest::MD5;
use MIME::Base64;
use strict;
use constant DEFAULT_URI => 'foo.bar';
sub handler {
my $r = shift;
my $debug = $r->dir_config('EBKLoginDebug') || 0;
....
}
strange: sometimes it seems to work, at least in one httpd-process,
when i hit refresh many times i sometimes get a correct answer and
mostly the error message. now segfaults in error log etc.
i know that dir_config is from Apache2::RequestUtil, i thought this
would have been loaded with Apache::Request. When i now add "use
Apache2::RequestUtil" or "use ARP::Table" in my coding the script is
working again.
so, do really i have to use the additinal "use Apache2::RequestUtil"?
can RequestUtil be loaded through some other modul? strange thing is,
that we have several webservers with this configuration (some older
version of supporting scritps, but apache/mod_perl is quite the same)
and there everything is working.
i don't know where to look further, can't see big differences. any
hints, thanxs
markus
------------------------------
Date: Tue, 28 Aug 2007 05:09:36 -0700
From: markus.rietzler@rzf.fin-nrw.de
Subject: mod_perl: can't locate object method...
Message-Id: <1188302976.013375.269640@g4g2000hsf.googlegroups.com>
hi group,
i have the following problem: two servers, identically setup - at
least i used the same files and when comparing everything (almost all)
looks identical. both are configured with apche 2.0.x, mod_perl2.
on both servers a mod_perl modul is configured in httpd.conf. but when
running on the new server i've installed i get
Can't locate object method "dir_config" via package
"Apache2::RequestRec" at /opt/perl5/lib/site_perl/5.8.7/foo/
redirect.pm line 21.
this is the beginning of the modul:
package foo::redirect;
use Apache2::Const qw(:common HTTP_MOVED_TEMPORARILY);
use Apache2::Log ();
use Apache2::URI ();
use Apache2::Connection();
use Apache2::Request;
use Apache2::SubRequest();
use Digest::MD5;
use MIME::Base64;
use strict;
use constant DEFAULT_URI => 'foo.bar';
sub handler {
my $r = shift;
my $debug = $r->dir_config('EBKLoginDebug') || 0;
....
}
strange: sometimes it seems to work, at least in one httpd-process,
when i hit refresh many times i sometimes get a correct answer and
mostly the error message. now segfaults in error log etc.
i know that dir_config is from Apache2::RequestUtil, i thought this
would have been loaded with Apache::Request. When i now add "use
Apache2::RequestUtil" or "use ARP::Table" in my coding the script is
working again.
so, do really i have to use the additinal "use Apache2::RequestUtil"?
can RequestUtil be loaded through some other modul? strange thing is,
that we have several webservers with this configuration (some older
version of supporting scritps, but apache/mod_perl is quite the same)
and there everything is working.
i don't know where to look further, can't see big differences. any
hints, thanxs
markus
------------------------------
Date: Tue, 28 Aug 2007 05:07:37 -0700
From: markus.rietzler@rzf.fin-nrw.de
Subject: mod_perl:
Message-Id: <1188302857.213507.283120@22g2000hsm.googlegroups.com>
hi group,
i have the following problem: two servers, identically setup - at
least i used the same files and when comparing everything (almost all)
looks identical. both are configured with apche 2.0.x, mod_perl2.
on both servers a mod_perl modul is configured in httpd.conf. but when
running on the new server i've installed i get
Can't locate object method "dir_config" via package
"Apache2::RequestRec" at /opt/perl5/lib/site_perl/5.8.7/foo/
redirect.pm line 21.
this is the beginning of the modul:
package foo::redirect;
use Apache2::Const qw(:common HTTP_MOVED_TEMPORARILY);
use Apache2::Log ();
use Apache2::URI ();
use Apache2::Connection();
use Apache2::Request;
use Apache2::SubRequest();
use Digest::MD5;
use MIME::Base64;
use strict;
use constant DEFAULT_URI => 'foo.bar';
sub handler {
my $r = shift;
my $debug = $r->dir_config('EBKLoginDebug') || 0;
....
}
strange: sometimes it seems to work, at least in one httpd-process,
when i hit refresh many times i sometimes get a correct answer and
mostly the error message. now segfaults in error log etc.
i know that dir_config is from Apache2::RequestUtil, i thought this
would have been loaded with Apache::Request. When i now add "use
Apache2::RequestUtil" or "use ARP::Table" in my coding the script is
working again.
so, do really i have to use the additinal "use Apache2::RequestUtil"?
can RequestUtil be loaded through some other modul? strange thing is,
that we have several webservers with this configuration (some older
version of supporting scritps, but apache/mod_perl is quite the same)
and there everything is working.
i don't know where to look further, can't see big differences. any
hints, thanxs
markus
------------------------------
Date: Tue, 28 Aug 2007 19:13:10 -0000
From: jkstill <jkstill@gmail.com>
Subject: Re: Most Appropriate Data Structure/Method
Message-Id: <1188328390.597780.154340@m37g2000prh.googlegroups.com>
On Aug 27, 9:44 am, Pat McDonnell <kc9...@arrl.net> wrote:
> Hello -
>
> I'm working on a script in which the user provides a path, and the script
> does something based on that path. I want to develop some type of
> association between paths, and actions to perform. For instance, take the
> following:
>
> Path Action
> ----------------------
> /home &home()
> /home/luser &luser()
> /home/luser/abc &luserabc();
>
> So, if the user passes /home/luser, &luser would be executed. If the user
> passes /home/luser/xyz, &luser would still be executed, as it is the most
> specific match for that path. If /home/anotheruser is passed, &home would
> be executed, as that is the most specific match. Does this make sense?
>
> So, my question is, is there any type of data structure/module that is best
> for this? I could hack something together with regex's and loops easily
> enough, but I was hoping there would be something "cleaner." I've looked
> at a trie, but that seems to be the opposite of what I want. Thanks.
>
> --
> Posted via a free Usenet account fromhttp://www.teranews.com
This looks promising:
http://www.perlmonks.org/index.pl?node=429761
------------------------------
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 803
**************************************