[29672] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 916 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 8 16:10:17 2007

Date: Mon, 8 Oct 2007 13:09:09 -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           Mon, 8 Oct 2007     Volume: 11 Number: 916

Today's topics:
        Extended regexes - "(?<...)" construct. <Cloink_Friggson@ntlworld.com>
    Re: Extended regexes - "(?<...)" construct. xhoster@gmail.com
    Re: FAQ 5.5 How can I copy a file? <bik.mido@tiscalinet.it>
    Re: FAQ 5.5 How can I copy a file? <ben@morrow.me.uk>
    Re: FAQ 5.5 How can I copy a file? <brian.d.foy@gmail.com>
        how to do operation on a mapped drive <nitindutt2005@gmail.com>
    Re: how to do operation on a mapped drive <rkb@i.frys.com>
        Perl on WinXP: transliteration produces different resul <hh@hh.phys.gwu.edu>
    Re: Perl on WinXP: transliteration produces different r <ben@morrow.me.uk>
    Re: Perl on WinXP: transliteration produces different r <hh@hh.phys.gwu.edu>
    Re: Perl on WinXP: transliteration produces different r <m@rtij.nl.invlalid>
    Re: print a number in hex <bik.mido@tiscalinet.it>
        Regex problem <hendrik_maryns@despammed.com>
    Re: Regex problem <abigail@abigail.be>
    Re: Regex problem <lew@lewscanon.com>
    Re: Should an empty regex match everything (Randal L. Schwartz)
    Re: The Modernization of Emacs: terminology buffer and  <joostkremers@yahoo.com>
        threads, Sys::SigAction, alarm, timeout <LovingFox@gmail.com>
    Re: threads, Sys::SigAction, alarm, timeout <zentara@highstream.net>
    Re: threads, Sys::SigAction, alarm, timeout <m@rtij.nl.invlalid>
        www.yedil.com best hindi entertainment site  diprat7@gmail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 08 Oct 2007 10:41:52 -0700
From:  Cloink <Cloink_Friggson@ntlworld.com>
Subject: Extended regexes - "(?<...)" construct.
Message-Id: <1191865312.172829.148000@57g2000hsv.googlegroups.com>

Can anyone tell me why my version of Perl won't compile a so-called
positive lookbehind assertion.

Specifically, I want to strip JavaScript comments from a file, so I'm
looking for "//" on a line, but since JS code can use regexes too,
it's possible to have "//" in a js-regex, which clearly isn't a
comment.

If the "//" is preceded by backslash however, i.e. "\//", I can be
pretty sure that this does NOT represent a comment.  (I don't need
advice on when this rule might break - I have a very specific
purpose.)

Here's one piece of problematic (javascript) code
    .split(/\//); // split string at forward-slash delimiters.

My PERL regex, in attempting to identify a preceding backslash in the
js code, I WANT to look like this
    s/(?<[^\\])\/\/.*$//x
to identify two slashes on a line but not immediately preceded by a
backslash.

But the perl compiler tells me it doesn't understand:-
    Sequence (?<[...) not recognized in regex; [line cont..]
    marked by <-- HERE in m/(?<[ <-- HERE ^\\])//.*$/

Incidentally, if I replace the awkward "not-a-backslash" section of
the regex with a more simple "an x" section, I still get the same
compilation error, i.e.
    replace "[^\\]" with "x"

"perl -v" tells me
    This is perl, v5.8.8 built for MSWin32-x86-multi-thread
and
    Binary build 820 [274739] provided by ActiveState
    http://www.ActiveState.com
    Built Jan 23 2007 15:57:46

It's not my reference book that's wrong is it?  (Perl in a Nutshell,
2nd Ed, June 2002, O'Reilly.)

Thanks.



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

Date: 08 Oct 2007 17:51:00 GMT
From: xhoster@gmail.com
Subject: Re: Extended regexes - "(?<...)" construct.
Message-Id: <20071008135102.713$G4@newsreader.com>

Cloink <Cloink_Friggson@ntlworld.com> wrote:
>
> My PERL regex, in attempting to identify a preceding backslash in the
> js code, I WANT to look like this
>     s/(?<[^\\])\/\/.*$//x
> to identify two slashes on a line but not immediately preceded by a
> backslash.

In that case, wouldn't it make more sense to use negative look-behind?
If the line starts with //, then it is not preceded by a backslash, but
it is not preceded by a non-backslash, either.


>
> But the perl compiler tells me it doesn't understand:-
>     Sequence (?<[...) not recognized in regex; [line cont..]
>     marked by <-- HERE in m/(?<[ <-- HERE ^\\])//.*$/
>
> Incidentally, if I replace the awkward "not-a-backslash" section of
> the regex with a more simple "an x" section, I still get the same
> compilation error, i.e.
>     replace "[^\\]" with "x"
>
> "perl -v" tells me
>     This is perl, v5.8.8 built for MSWin32-x86-multi-thread
> and
>     Binary build 820 [274739] provided by ActiveState
>     http://www.ActiveState.com
>     Built Jan 23 2007 15:57:46
>
> It's not my reference book that's wrong is it?  (Perl in a Nutshell,
> 2nd Ed, June 2002, O'Reilly.)

The perldoc perlre says the positive look behind syntax is (?<=pattern).
If your reference book omits then "=", then it is wrong.

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: Mon, 08 Oct 2007 11:19:15 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: FAQ 5.5 How can I copy a file?
Message-Id: <octjg35ufllpajojbtqaitho461bfmmh0o@4ax.com>

On Sun, 7 Oct 2007 22:04:13 +0100, Ben Morrow <ben@morrow.me.uk>
wrote:

>Because it's Hard. The most important advantage to using cp(1), AFAICS,
>is that it knows about attributes files have that are particular to your
>OS; writing a Perl module to locate and copy all of these is not an easy
>task.

BTW: isn't cp's code available from a shared lib for which bindings
could be built for Perl?


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: Mon, 8 Oct 2007 14:00:38 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: FAQ 5.5 How can I copy a file?
Message-Id: <m8mpt4-f61.ln1@osiris.mauzo.dyndns.org>


Quoth Michele Dondi <bik.mido@tiscalinet.it>:
> On Sun, 7 Oct 2007 22:04:13 +0100, Ben Morrow <ben@morrow.me.uk>
> wrote:
> 
> >Because it's Hard. The most important advantage to using cp(1), AFAICS,
> >is that it knows about attributes files have that are particular to your
> >OS; writing a Perl module to locate and copy all of these is not an easy
> >task.
> 
> BTW: isn't cp's code available from a shared lib for which bindings
> could be built for Perl?

Not on my system. I believe some (?) Linuxes have such a library, but
most systems don't.

Ben



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

Date: Mon, 08 Oct 2007 08:31:09 -0500
From: brian d  foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 5.5 How can I copy a file?
Message-Id: <081020070831093719%brian.d.foy@gmail.com>

In article <d7unt4-83d.ln1@osiris.mauzo.dyndns.org>, Ben Morrow
<ben@morrow.me.uk> wrote:

> Quoth brian d  foy <brian.d.foy@gmail.com>:

> > Indeed, although I think we should fix File::Copy so it doesn't have
> > those problems. I'm not sure why nobody hasn't.

> Because it's Hard. 

Hard problems are the fun ones. :)


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

Date: Mon, 08 Oct 2007 11:20:15 -0000
From:  andy <nitindutt2005@gmail.com>
Subject: how to do operation on a mapped drive
Message-Id: <1191842415.854327.198690@g4g2000hsf.googlegroups.com>

I have a remote server and I have mapped one drive from that remote
server into my local machine to access a perticular directory in that.

But I have to restart my local machine again and again. So again i
have to reconnect to the mapped drive by giving the userid and
password.

As I have to copy a file from that mapped drive and run that file on
the local machine after restarting the local machine.

The above process i have to do for each new file added into that
mapped drive.
So the steps are:
1: detect the file added to the mapped drive.
2: copy to the local machine.
3: restart the local machine.
4: Run that copied file.
5: do the same process continuously so that each time a new file is
added to the mapped drive it will detect, copy the same file and
restart the machine.

How can this be done using perl.



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

Date: Mon, 08 Oct 2007 08:48:54 -0700
From:  Ron Bergin <rkb@i.frys.com>
Subject: Re: how to do operation on a mapped drive
Message-Id: <1191858534.848984.219540@g4g2000hsf.googlegroups.com>

On Oct 8, 4:20 am, andy <nitindutt2...@gmail.com> wrote:
> I have a remote server and I have mapped one drive from that remote
> server into my local machine to access a perticular directory in that.
>
> But I have to restart my local machine again and again. So again i
> have to reconnect to the mapped drive by giving the userid and
> password.
>
> As I have to copy a file from that mapped drive and run that file on
> the local machine after restarting the local machine.
>
> The above process i have to do for each new file added into that
> mapped drive.
> So the steps are:
> 1: detect the file added to the mapped drive.
> 2: copy to the local machine.
> 3: restart the local machine.
> 4: Run that copied file.
> 5: do the same process continuously so that each time a new file is
> added to the mapped drive it will detect, copy the same file and
> restart the machine.
>
> How can this be done using perl.

Why do you need to reboot your computer each time you copy a file?

Please make an attempt at writing the script then post it and specific
questions when you have a problem and we'll be happy to help.

If you need/want someone to write it for you, then you may want to
check out:
http://www.rentacoder.com/RentACoder/default.asp



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

Date: Mon, 08 Oct 2007 14:43:46 -0400
From: hh <hh@hh.phys.gwu.edu>
Subject: Perl on WinXP: transliteration produces different results on different machines
Message-Id: <13gkuj29gaapn33@corp.supernews.com>

I use the ActiveState Perl installation 5.8.8 (build 822) on two 
different Windows XP machines. The following simple code

$string = "ABCxyz";
print "$string\n";
$string = ~ tr/A-Z/a-z/;
print "$string\n";

produces different results on the two machines. On machine 1, I obtain

ABCxyz
abcxyz

as it should be, and on machine 2, I get

ABCxyz
4294967295

Any idea what's going? --- I presume it'll be something rather trivial 
since I am a Perl novice, but searching around everywhere I haven't been 
able to find anything.

Thanks.
--hh


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

Date: Mon, 8 Oct 2007 20:53:25 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Perl on WinXP: transliteration produces different results on different machines
Message-Id: <leeqt4-2c71.ln1@osiris.mauzo.dyndns.org>


Quoth hh <hh@hh.phys.gwu.edu>:
> I use the ActiveState Perl installation 5.8.8 (build 822) on two 
> different Windows XP machines. The following simple code
> 
> $string = "ABCxyz";
> print "$string\n";
> $string = ~ tr/A-Z/a-z/;
> print "$string\n";
> 
> produces different results on the two machines. On machine 1, I obtain
> 
> ABCxyz
> abcxyz
> 
> as it should be, and on machine 2, I get
> 
> ABCxyz
> 4294967295
> 
> Any idea what's going? --- I presume it'll be something rather trivial 
> since I am a Perl novice, but searching around everywhere I haven't been 
> able to find anything.

The =~ operator must be written with no whitespace. What you have above
parses as

    $string = (~ tr/A-Z/a-z);

that is, it performs tr/// on $_, which returns a count of translations,
and then assigns the bitwise-not of that value to $string. I don't
really understand why it 'works' on one of your machines, unless the
script is not in fact the same in both cases.

The -p option to B::Deparse can be helpful in these cases:

    ~% perl -MO=Deparse,-p -e'$x = ~ tr/A-Z/a-z/'
    ($x = (~tr/A-Z/a-z/));
    -e syntax OK

(translate as appropriate for cmd.exe, of course...).

FYI, if you set $\ you don't need to explicitly print the "\n" at the
ends of you lines...

Ben



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

Date: Mon, 08 Oct 2007 15:42:58 -0400
From: hh <hh@hh.phys.gwu.edu>
Subject: Re: Perl on WinXP: transliteration produces different results on different machines
Message-Id: <13gl222t4q6lb4d@corp.supernews.com>

On 10/8/2007 2:43 PM, hh wrote:
> I use the ActiveState Perl installation 5.8.8 (build 822) on two 
> different Windows XP machines. The following simple code
> 
> $string = "ABCxyz";
> print "$string\n";
> $string = ~ tr/A-Z/a-z/;
> print "$string\n";
> 
> produces different results on the two machines. On machine 1, I obtain
> 
> ABCxyz
> abcxyz
> 
> as it should be, and on machine 2, I get
> 
> ABCxyz
> 4294967295
> 
> Any idea what's going? --- I presume it'll be something rather trivial 
> since I am a Perl novice, but searching around everywhere I haven't been 
> able to find anything.
> 
> Thanks.
> --hh

Never mind, I found the error. Somehow I had erroneously inserted a 
blank space into the binding operator (=~) in the code for machine 2 
(reproduced above) which was not present in the code for machine 1.

I knew it was a trivial error.
Sorry!


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

Date: Mon, 8 Oct 2007 21:58:47 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Perl on WinXP: transliteration produces different results on different machines
Message-Id: <pan.2007.10.08.19.54.58@rtij.nl.invlalid>

On Mon, 08 Oct 2007 14:43:46 -0400, hh wrote:

> I use the ActiveState Perl installation 5.8.8 (build 822) on two
> different Windows XP machines. The following simple code
> 
> $string = "ABCxyz";
> print "$string\n";
> $string = ~ tr/A-Z/a-z/;
> print "$string\n";
> 
> produces different results on the two machines. On machine 1, I obtain
> 
> ABCxyz
> abcxyz
> 
> as it should be, and on machine 2, I get
> 
> ABCxyz
> 4294967295
> 
> Any idea what's going? --- I presume it'll be something rather trivial
> since I am a Perl novice, but searching around everywhere I haven't been
> able to find anything.

[martijn@cow ~]$ perl -e '$string = "ABCxyz";
print "$string\n";
$string = ~ tr/A-Z/a-z/;
print "$string\n";'
ABCxyz
18446744073709551615
[martijn@cow ~]$ perl -e '$string = "ABCxyz";
print "$string\n";
$string =~ tr/A-Z/a-z/;
print "$string\n";'
ABCxyz
abcxyz
[martijn@cow ~]$ 

Notice the difference between the two programs!

M4


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

Date: Mon, 08 Oct 2007 11:24:06 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: print a number in hex
Message-Id: <jktjg395gne0d91ko8si30cs0lffqm4lrv@4ax.com>

On Sun, 07 Oct 2007 17:51:02 -0000, Amir <sting.t2@gmail.com> wrote:

>I have one more question,

Then you'd better start a new thread...


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: Mon, 08 Oct 2007 14:48:11 +0200
From: Hendrik Maryns <hendrik_maryns@despammed.com>
Subject: Regex problem
Message-Id: <fed8ua$v7n$1@newsserv.zdv.uni-tuebingen.de>

(This is in Java, but the regex is general, therefore x-post to
c.l.p.m., f-up to c.l.j.h.)

Hi all,

I want to discard the header of some file.  The header is everything
before a line beginning with "#BOS".  However, I do not want #BOS to be
part of the match, since I need it later on.

I thought of using a regex to do that.  I came up with

 .*(?s)(?=#BOS)

However, this gave me nothing.
(To be precise, I have

Scanner corpus = new Scanner(inFile);
Pattern header = Pattern.compile(".*(?s)(?=#BOS)", Pattern.MULTILINE);
corpus.skip(header);

and it gives me

java.util.NoSuchElementException
	at java.util.Scanner.skip(Scanner.java:1706)
	at
de.uni_tuebingen.sfb.lichtenstein.binarytrees.Converter2.main(Converter2.java:61)

so if any of the Java people sees a problem there, please point out.)

So to pinpoint my problem: I want a regex which matches any number of
lines until it finds a line beginning with #BOS, but does not include
#BOS in the match.

Other tries looked like this:

 .*?(?s)(?=#BOS)
(.|\n)*?(?=#BOS)  (this freezes the program)
 .*(?=#BOS) with MULTLINE uption to Pattern.Compile
 .*(?s)^(?=#BOS)

and several others, but I find no solution.  So my last resort is asking
here.

TIA, H.
-- 
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html


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

Date: 08 Oct 2007 16:08:52 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: Regex problem
Message-Id: <slrnfgkler.hcg.abigail@alexandra.abigail.be>

                                                       _
Hendrik Maryns (hendrik_maryns@despammed.com) wrote on VCLI September
MCMXCIII in <URL:news:fed8ua$v7n$1@newsserv.zdv.uni-tuebingen.de>:
**  (This is in Java, but the regex is general, therefore x-post to
**  c.l.p.m., f-up to c.l.j.h.)

I don't read the latter, so I won't post just there. Followups set to
clpm though.

**  I want to discard the header of some file.  The header is everything
**  before a line beginning with "#BOS".  However, I do not want #BOS to be
**  part of the match, since I need it later on.
**  
**  I thought of using a regex to do that.  I came up with
**  
**  .*(?s)(?=#BOS)

That changes the meaning of . *after* matching .*

    /(?s).*(?=#BOS)/

would do, although I would write it as:

    /^.*(?=#BOS)/s

Note that due to the .*, it will match everything up to the *last* occurance
of #BOS. You might want to write that differently if you want to remove things
up to the first #BOS, for instance (untested):

   /^[^#]*(?:#(?!BOS)[^#]*)*#BOS/

which does some loop unrolling, avoids the usage of .*? (which can be
costly), and doesn't need (?s) because there's no . in the pattern.

Note that I anchored the pattern to the beginning of the string. This 
should speed up the case where no #BOS is present in the string matched
against.


Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
 .qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
 .qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'


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

Date: Mon, 08 Oct 2007 13:43:24 -0400
From: Lew <lew@lewscanon.com>
Subject: Re: Regex problem
Message-Id: <ZKudnQc9tqGh8ZfanZ2dnUVZ_rvinZ2d@comcast.com>

> Hendrik Maryns (hendrik_maryns@despammed.com) wrote on VCLI September
> MCMXCIII in <URL:news:fed8ua$v7n$1@newsserv.zdv.uni-tuebingen.de>:
> **  (This is in Java, but the regex is general, therefore x-post to
> **  c.l.p.m., f-up to c.l.j.h.)

Abigail wrote:
> I don't read the latter, so I won't post just there. Followups set to
> clpm though.

But the OP /does/ read clj.help, and pointed out that his problem is in Java, 
so redirecting the answers away from clj.help is pure arrogance.

-- 
Lew


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

Date: Mon, 08 Oct 2007 05:09:03 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Should an empty regex match everything
Message-Id: <861wc524gw.fsf@blue.stonehenge.com>

>>>>> "Mintcake" == Mintcake  <tony@skelding.co.uk> writes:

Mintcake> #!/usr/bin/env perl

Beware this usage... if another user (such as the webserver) has a different
PATH, they'll get a different Perl for this.  Not good in the general case.

-- 
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: 8 Oct 2007 11:32:13 GMT
From: Joost Kremers <joostkremers@yahoo.com>
Subject: Re: The Modernization of Emacs: terminology buffer and keybinding
Message-Id: <slrnfgk58g.2ps.joostkremers@j.kremers4.news.arnhem.chello.nl>

bbound@gmail.com wrote:
> Don't both "man" and those words for measurement come ultimately from
> words for "hand" (similarly to words like "manual", as in labor)?

no. "manual" is derived from latin "manus" meaning "hand". the word "man"
is related to (though not directly derived from) "mind", and the latin word
"mens", which means "mind".


-- 
Joost Kremers                                      joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)


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

Date: Mon, 08 Oct 2007 12:17:48 -0000
From:  "LovingFox@gmail.com" <LovingFox@gmail.com>
Subject: threads, Sys::SigAction, alarm, timeout
Message-Id: <1191845868.297779.9100@y42g2000hsy.googlegroups.com>

I've got some kind of problem using threads module with Sys::SigAction
module. Look to this too examples:

1. The first (function 't' w/o threads) works good as I need:
-------------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
use Sys::SigAction qw( set_sig_handler );
t();
sub t {
 eval {
    set_sig_handler( 'ALRM', sub { die 'alarm!' } );
    alarm(1);
    sleep(2); # here is some usefull code instead 'sleep'
    alarm(0);
 };
 print "end '$@'\n";
}
-------------------------------------------------------------------------

2. The second (function 't' through threads) prints error I cannot
understand:
-------------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
use threads;
use Sys::SigAction qw( set_sig_handler timeout_call );
threads->new( \&t )->join();
sub t {
 eval {
    set_sig_handler( 'ALRM', sub { die 'alarm!' } );
    alarm(1);
    sleep(2);
    alarm(0);
 };
 print "end '$@'\n";
}
-------------------------------------------------------------------------
This code print this:
Signal SIGALRM received, but no signal handler set.

How it can be overcome?



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

Date: Mon, 08 Oct 2007 11:12:56 -0400
From: zentara <zentara@highstream.net>
Subject: Re: threads, Sys::SigAction, alarm, timeout
Message-Id: <12ikg39u49tjeqt33in221ib00cm3nbap5@4ax.com>

On Mon, 08 Oct 2007 12:17:48 -0000, "LovingFox@gmail.com"
<LovingFox@gmail.com> wrote:

>I've got some kind of problem using threads module with Sys::SigAction
>module. Look to this too examples:
>
>1. The first (function 't' w/o threads) works good as I need:
>-------------------------------------------------------------------------
>#!/usr/bin/perl -w
>use strict;
>use Sys::SigAction qw( set_sig_handler );
>t();
>sub t {
> eval {
>    set_sig_handler( 'ALRM', sub { die 'alarm!' } );
>    alarm(1);
>    sleep(2); # here is some usefull code instead 'sleep'
>    alarm(0);
> };
> print "end '$@'\n";
>}
>-------------------------------------------------------------------------
>
>2. The second (function 't' through threads) prints error I cannot
>understand:
>-------------------------------------------------------------------------
>#!/usr/bin/perl -w
>use strict;
>use threads;
>use Sys::SigAction qw( set_sig_handler timeout_call );
>threads->new( \&t )->join();
>sub t {
> eval {
>    set_sig_handler( 'ALRM', sub { die 'alarm!' } );
>    alarm(1);
>    sleep(2);
>    alarm(0);
> };
> print "end '$@'\n";
>}
>-------------------------------------------------------------------------
>This code print this:
>Signal SIGALRM received, but no signal handler set.
>
>How it can be overcome?

I don't know about how Sys::Sigaction works, but threads and ALARM
and/or signals don't work with threads. The parent thread receives all
signals, so using them in threads is useless unless you have the parent
handle them.  

zentara


-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html


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

Date: Mon, 8 Oct 2007 22:03:59 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: threads, Sys::SigAction, alarm, timeout
Message-Id: <pan.2007.10.08.20.00.11@rtij.nl.invlalid>

On Mon, 08 Oct 2007 11:12:56 -0400, zentara wrote:

> I don't know about how Sys::Sigaction works, but threads and ALARM
> and/or signals don't work with threads. The parent thread receives all
> signals, so using them in threads is useless unless you have the parent
> handle them.
> 
> zentara

from perlthrtut:

] Similarly, mixing signals and threads should not be attempted.
] Implementations are platform-dependent, and even the POSIX semantics
] may not be what you expect (and Perl doesn’t even give you the full
] POSIX API).

So I would not even count on the main thread receiving all signals. Or am 
I missing something here?

M4


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

Date: Mon, 08 Oct 2007 07:55:32 -0700
From:  diprat7@gmail.com
Subject: www.yedil.com best hindi entertainment site
Message-Id: <1191855332.870415.36630@o3g2000hsb.googlegroups.com>

www.yedil.com best hindi entertainment site
with vidoes,photo sharing,photo rating features
its really gona rock you
www.yedil.com



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

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


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