[29287] in Perl-Users-Digest
Perl-Users Digest, Issue: 531 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 18 18:09:51 2007
Date: Mon, 18 Jun 2007 15:09:05 -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, 18 Jun 2007 Volume: 11 Number: 531
Today's topics:
Re: 12 hour clock and offset problem anno4000@radom.zrz.tu-berlin.de
Re: 12 hour clock and offset problem <dbroda@gmail.com>
Re: could XML::Simple handling chinese character? <bart.lateur@pandora.be>
Discover As Beginning Successful Business In Internet. pacovegavilla@yahoo.com.mx
Re: For Loop <scobloke2@infotop.co.uk>
Re: How to test whether something is a func,method or v <muede73@gmx.de>
lightweight access to large data structures? ivowel@gmail.com
Re: lightweight access to large data structures? usenet@DavidFilmer.com
Re: Massive Memory Structures ruu@cwcom.net
Re: Massive Memory Structures <nospam-abuse@ilyaz.org>
paragraph mode <larry.grant.dc@gmail.com>
Re: The Modernization of Emacs (Joel J. Adamson)
Re: The Modernization of Emacs <hal@thresholddigital.com>
Re: Which Perl 5 OO extension can be seen as "standard" <ilias@lazaridis.com>
Re: Which Perl 5 OO extension can be seen as "standard" <ilias@lazaridis.com>
Re: Win32: How to quit perl script during log off autom <rprp@gmx.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 18 Jun 2007 11:03:34 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: 12 hour clock and offset problem
Message-Id: <5dn746F345q92U1@mid.dfncis.de>
Dr.Ruud <rvtol+news@isolution.nl> wrote in comp.lang.perl.misc:
> Kenetic schreef:
>
> > perl's mod doesn't work very well with fractions
[...]
> Nothing is mentioned there about fractional behaviour. But I was never
> surprised because *in my world*, "modulus" operates on integers. ...
That's customary, but it's an unnecessary restriction. The "x mod y"
operation can be consistently defined for all real x and y through
x mod y = x - y*floor(x/y) (y != 0)
y mod 0 = x
(Yes, a zero "denominator" is admissible.) Cf. Knuth, _TAOCP_, 1.2.4
(Vol 1).
Anno
------------------------------
Date: Mon, 18 Jun 2007 13:04:16 -0000
From: Kenetic <dbroda@gmail.com>
Subject: Re: 12 hour clock and offset problem
Message-Id: <1182171856.902096.22610@i38g2000prf.googlegroups.com>
On Jun 18, 1:27 am, Brian McCauley <nobul...@gmail.com> wrote:
> Sorry, yes.
>
> $hours += 12 if $ampm eq 'pm';
>
> Should, of course, read:
>
> $hours += 12 if $ampm eq 'pm' xor $hours eq '12';
Hey thanks Brian. It's rather amusing that about 15 minutes ago I
solved it myself, with a lot of the help posted here, but not really
copy and paste--started from the beginning and persevered till the
finish. Then I looked over here again. Even more amusing is that my
code needed to round some minute fractions, and I used a small snippet
Anno posted in another thread (didn't think it was related to this
newsgroup, but it was).
Yours is much more compact then what I wrote, and I learned quite a
bit from it before and again after--never seen xor being used before,
that's neat!
my $offset = -3.5;
my $tempTime = "9:40 am";
sub myMod {
my ( $a, $b ) = @_;
my $div = $a / $b;
return $a - int( $div ) * $b;
}
sub rnd {
my ( $x, $factor) = @_;
$factor*sprintf '%.0f', $x/$factor;
}
sub getutc {
my ( $time, $GMTOffset ) = @_;
my ( $hrs, $mins, $apm ) = $time =~ /(\d+):(\d\d)\s+([ap]m)/;
$tempPM = $apm;
if (($apm eq "pm") && ($hrs == 12)) {
$tempMins = $hrs * 60;
} elsif (($apm eq "am") && ($hrs == 12)) {
$tempMins = 0;
} elsif ($apm eq "pm") {
$hrs+=12;
$tempMins = $hrs * 60;
} elsif ($apm eq "am") {
$tempMins = $hrs * 60;
}
$tempMins += $mins;
if (myMod($offset, int($offset)) == -0.5) {
$tempMins += 30;
}
$tempMins -= (int($offset) * 60);
$tempMins %= 1440;
if ($tempMins >= 720) {
$apm = "pm";
} else {
$apm = "am";
}
$hrF = ($tempMins / 60);
if (int($hrF > 12)) {
$hrs = int($hrF-12);
} else {
$hrs = int($hrF);
}
$minsF = ($hrF - int($hrF));
$mins = rnd(($minsF * 60),1/2);
$mins = sprintf("%02d", $mins);
return sprintf("%2d:%02d %s", $hrs == 0 ? 12 : $hrs, $mins, $apm);
}
my $theTime = getutc($tempTime, $offset );
print "\nCurrent time: $tempTime\n",
"Adjust $offset hours\n\n",
"Adjusted to: $theTime\n";
At this point it would be trivial to ask how could I optimize or
produce more efficient code, since it's basically already been
discussed.
Consider this issue solved. For now ;)
Thanks!
------------------------------
Date: Mon, 18 Jun 2007 21:45:40 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: could XML::Simple handling chinese character?
Message-Id: <i7vd73p4vtemjq4bvg4nootjv0lj3tkvii@4ax.com>
Ian Wilson wrote:
>As others have said, it seems likely that the OP's XML file is actually
>encoded in GB2312, not in UTF8 as specified in it's XML declaration.
Which would be an excellent reason for any XML parser to barf.
--
Bart.
------------------------------
Date: Mon, 18 Jun 2007 07:29:54 -0700
From: pacovegavilla@yahoo.com.mx
Subject: Discover As Beginning Successful Business In Internet.
Message-Id: <1182176994.943276.182740@q19g2000prn.googlegroups.com>
Discover As Beginning Successful Business In Internet.
If you believed that to begin business in internet single era for
experts........ This very mistaken one!
Discover our system proven to begin business in Internet. Entering
RIGHT NOW
http://www.freedom.ws/pacovegavilla
Alone to visit our place web he/she is entitled to request our
confidential report valued totally FREE in more than US $100:
Francisco Fermin Vega Villa
Director of http://www.freedom.ws/pacovegavilla
"US wins $21.699 Monthly Before 20 Months. Discover As People With
Minimum Knowledge In Internet they are Creating A Great Fortune With
Our Proven System Of Business."
http://www.freedom.ws/pacovegavilla
------------------------------
Date: Mon, 18 Jun 2007 11:38:05 +0100
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: Re: For Loop
Message-Id: <46766090$0$27852$db0fefd9@news.zen.co.uk>
shapper wrote:
> On Jun 17, 5:23 pm, "Dr.Ruud" <rvtol+n...@isolution.nl> wrote:
>
>> Paul Lalli schreef:
<English explanation of OP's Perl code>
>
> I tried to convert the code but until now I wasn't success ... I am
> maybe doing something wrong here.
>
> Does anyone knows what would be the equivalent code in C# or VB.NET?
I'd post in a C# newsgroup, quoting Paul's explanation of the Perl, also
cut & paste the C# you have written, state what output you get, state
why you think the output is wrong and ask for suggestions.
I'd try newsgroup microsoft.public.dotnet.languages.csharp.
------------------------------
Date: Mon, 18 Jun 2007 15:50:46 +0200
From: muede <muede73@gmx.de>
Subject: Re: How to test whether something is a func,method or var
Message-Id: <1182174664.309262@arno.fh-trier.de>
anno4000@radom.zrz.tu-berlin.de wrote:
>
> How does a situation like this happen?
>
I wrote a script that collects informations about modules
by "parsing" through the manuals.
This works pretty good most of the time, but in some cases
I need a way to determine whether `something` is
an object-method or a function or ...
>
> Read up about typeglobs in perldata.
>
Thanks, ill do that.
-ap
------------------------------
Date: Mon, 18 Jun 2007 21:20:35 -0000
From: ivowel@gmail.com
Subject: lightweight access to large data structures?
Message-Id: <1182201635.263088.204000@g4g2000hsf.googlegroups.com>
dear perl experts---
I have a 300MB .csv data file (60MB compressed) that I need to read,
but not write to:
key-part1,key-part2,data1,data2,data3
ibm,2003/01,0.2,0.3,0.4
ibm,1972/01,0.5,0.3,NaN
sunw,2003/01,0.3,NaN,0.1
...
the key-part1+key-part2 combination is unique, but neither key alone
is unique.
my first idea to use this data in perl was a bit naive: create a hash
of hashes, so that I can find data or iterate over all data items that
match only one of the two keys. Something like $data1->{ibm}-
>{192601} and $data1->{192601}->{ibm}. great idea indeed, except
that after it gobbled up about 4GB of RAM, my perl program died. this
would have been nice.
I can think of a couple of methods that I could use. I could read the
data with a C program, and then have perl query my C program (e.g.,
through a socket). yikes. I could copy (yikes) the data into a data
base and access it through a data base modules, though I am not sure
what data base I should use for this purpose. (I need not one-key
access, but two key multiple-record access.) or I could do the
combination, and put the data into an SQL data base and learn SQL just
so that I can quickly access my data file. yikes and yikes. maybe
perl6 could do better, but perl6 isn't around yet. is there a way to
code so that perl5 becomes more memory efficient?
This can't be an obscure problem. What is the recommended light-
weight way of dealing with such large-data situations in perl5 ?
advice appreciated...
sincerely,
/iaw
------------------------------
Date: Mon, 18 Jun 2007 21:35:36 -0000
From: usenet@DavidFilmer.com
Subject: Re: lightweight access to large data structures?
Message-Id: <1182202536.362164.134310@z28g2000prd.googlegroups.com>
On Jun 18, 2:20 pm, ivo...@gmail.com wrote:
> I have a 300MB .csv data file...
> it gobbled up about 4GB of RAM
There's no reason why 300 MB of input data should consume 4 GB when
imported into a Perl data structure. I have a feeling there is an
infinite loop or gross inefficiency or some other problem in your
program.
Consider using one of the many CSV parsers available on http://search.cpan.org.
Or show us your file reading and parsing code; maybe we can spot the
problem.
--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)
------------------------------
Date: Mon, 18 Jun 2007 07:43:54 -0700
From: ruu@cwcom.net
Subject: Re: Massive Memory Structures
Message-Id: <1182177834.235773.78540@o61g2000hsh.googlegroups.com>
On Jun 18, 3:29 am, Ilya Zakharevich <nospam-ab...@ilyaz.org> wrote:
> [A complimentary Cc of this posting was sent to
>
> <r...@cwcom.net>], who wrote in article <1181948380.781819.311...@q75g2000hsh.googlegroups.com>:
>
> > open(FILE,"$filename");
> > $bigvar = <FILE>;
> > close FILE;
>
> Typical users underestimate the amount of memory used by "a
> statement". E.g., if no optimizations were present, the statement
> above could use about 50GB+. Look at it:
>
> a) you read data of unknown size into a temporary variable; the buffer
> used by this variable is realloc()ed about 150 times. Assume the
> "trail" of old buffers takes about 35GB; then the total size used is
> 40G + memory overhead on a 5GB allocation.
>
> b) The temporary variable is copied inot $bigvar; (another 5GB + memory
> overhead);
>
> c) The copied value is also the value of the statement; another 5G +
> memory overhead is sitting on Perl stack.
>
> AFAIR, "b" and "c" are currently optimized away. However, "a" is
> fully dependent on the malloc() implementation, and (unless you use
> Perl's malloc()) are out of Perl control. (Perl's malloc() would use
> about 8GB.)
>
> My advice is to redo the test with 3GB allocation, and check the
> actual memory usage.
>
> Hope this helps,
> Ilya
The first thing I did with this script was use a 3G memory size, which
used a tiny bit more than 3G of memory and worked fine (have you
tested you logic on your architecture - what you describe just doesn't
seem to happen on my Solaris boxes). Then I moved up to over 4G, and
it failed with "Out of Memory!", which I expected. This really isn't
the point anyway - the file example was just to try any memory
structure greater than 4G to see what would happen, and if the script
had sat there and used memory all the way up to 50G+ (which honestly
wouldn't have failed on the servers I am using anyway), then I would
probably have noticed on my 10th or 11th attempt at doing this while
watching top/prstat. What I actually needed to work was a sizeable
hash mapping customer ID's to customer details, but since it is a lot
more difficult writing a test script that keeps memory under control,
I went with the much simpler "read a file" test script instead.
My point is fairly simple - it doesn't matter what data structure I am
using, be it reading a huge file into a single variable, or
maintaining a hash of 50+million entries, as soon as the script uses
4G of memory, it dies. I'm about as sure as I can be that the problem
isn't in the code, but either in the way that perl was built, or
something that the OS was doing. Since this isn't a Solaris group,
mostly I was hoping someone with a lot of experience building perl
might be able to make some suggestions on optimizing the build.
Dave
------------------------------
Date: Mon, 18 Jun 2007 21:08:36 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Massive Memory Structures
Message-Id: <f56s8k$1cb2$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
<ruu@cwcom.net>], who wrote in article <1182177834.235773.78540@o61g2000hsh.googlegroups.com>:
> The first thing I did with this script was use a 3G memory size, which
> used a tiny bit more than 3G of memory and worked fine (have you
> tested you logic on your architecture - what you describe just doesn't
> seem to happen on my Solaris boxes).
Then Solaris' malloc() got better than it used to be...
> Then I moved up to over 4G, and it failed with "Out of Memory!"
From watching comp.sys.sun.hardware, I also remember some mentions of
"secret handshakes" :-(. Look for postings by Casper.
But the most probable cause is wrong compiler flags. You did not post
your -V (not that I know correct flags for full 64bit on Solaris)...
Hope this helps,
Ilya
------------------------------
Date: Mon, 18 Jun 2007 20:56:14 -0000
From: Larry <larry.grant.dc@gmail.com>
Subject: paragraph mode
Message-Id: <1182200174.670564.13280@m36g2000hse.googlegroups.com>
Is there any exact definition of "paragraph mode", i.e.
$/ = '';
Everything I've seen has been somewhat vague. In particular, I am
noticing on ActiveState/Win32 that the Hex sequence "0d 0a 20 0d 0a"
is NOT being treated as a "paragraph boundary" (quite annoyingly).
For some reason the space character alone on a line invalidates it.
However, I am quite sure I have seen "0a 20 0a" treated as a
"paragraph boundary" under Linux (can't test it so easily right now).
What is the correct behavior?
------------------------------
Date: Mon, 18 Jun 2007 10:35:33 -0400
From: jadamson@partners.org (Joel J. Adamson)
Subject: Re: The Modernization of Emacs
Message-Id: <873b0p9vpm.fsf@W0053328.mgh.harvard.edu>
Xah Lee <xah@xahlee.org> writes:
> ----------------------------------------
> SIMPLE CHANGES
>
> In the following, i describe some critical changes that are also very
> easy to fix in emacs. If emacs officially adopt these changes, i think
> it will make a lot people, at least programers, like emacs and choose
> emacs as their text editor.
The problem with this line of thinking is that it aims to make Emacs
appeal to people -- I think it is rather the other way around.
Certain people appeal to Emacs: certain kinds of people like Emacs
and the way it is set up, and they change it to suit their needs.
Among your changes, I found none that made sense to me, a person who
used Unix before Windows became widely used. For people like me, who
always preferred Unix, changes like changing "buffer" to "opened file"
seem inefficient and unnecessary.
Sorry -- this totally falls flat. It won't make Emacs more widely
used. The only thing that will make Emacs more widely used is making
people aware of it; as soon as I became aware of Emacs (from reading
Wikipedia, ironically), I began using it and I knew I was stuck with
it. It's not even important for the survival of Emacs that it be more
widely used -- it was never important in the last thirty years of its
history, why should it be important now that Microsoft Word is so
widely used?
Joel
--
Joel J. Adamson
Biostatistician
Pediatric Psychopharmacology Research Unit
Massachusetts General Hospital
Boston, MA 02114
(617) 643-1432
(303) 880-3109
------------------------------
Date: Mon, 18 Jun 2007 14:13:42 -0400
From: Hal Vaughan <hal@thresholddigital.com>
Subject: Re: The Modernization of Emacs
Message-Id: <5rWdnfcDQ4PLVuvbnZ2dnUVZ_qGjnZ2d@comcast.com>
Joel J. Adamson wrote:
> Xah Lee <xah@xahlee.org> writes:
>
>> ----------------------------------------
>> SIMPLE CHANGES
>>
>> In the following, i describe some critical changes that are also very
>> easy to fix in emacs. If emacs officially adopt these changes, i think
>> it will make a lot people, at least programers, like emacs and choose
>> emacs as their text editor.
>
> The problem with this line of thinking is that it aims to make Emacs
> appeal to people -- I think it is rather the other way around.
> Certain people appeal to Emacs: certain kinds of people like Emacs
> and the way it is set up, and they change it to suit their needs.
I worked for years as a special ed teacher and I learned that people have
different learning styles. It's not just learning, but it's perceiving and
working as well. Some people will always do better with a command line and
some will always do better with a GUI with point-and-click. That doesn't
mean one is smarter than the other or one is a true geek and one isn't.
It's just the way our brains are wired.
Emacs appeals to the type of personality that is often a hard core
programmer. It works for those that want to customize everything and have
full control over their environment AND do well with a command line rather
than a more visual and graphic environment. For those, emacs is probably
the best program for them.
Some people prefer to drive a Miata and some prefer a Dodge Ram. One isn't
better than the other, they're just different. Trying to make a Dodge Ram
look like a convertible so Miata lovers will want to use it is a waste.
It'll never be a Miata and the more people try to make it adaptable so it
can be one, the more they ruin what's special about it.
The more emacs is adapted for the non-technical, the more it'll lose what
makes it special and a good fit for programmers.
> Among your changes, I found none that made sense to me, a person who
> used Unix before Windows became widely used. For people like me, who
> always preferred Unix, changes like changing "buffer" to "opened file"
> seem inefficient and unnecessary.
It seems to me that is the kind of person emacs is written for. What will
it gain if a large number of non-technical people start using it in
a "non-emacs" mode?
> Sorry -- this totally falls flat. It won't make Emacs more widely
> used. The only thing that will make Emacs more widely used is making
> people aware of it; as soon as I became aware of Emacs (from reading
> Wikipedia, ironically), I began using it and I knew I was stuck with
> it. It's not even important for the survival of Emacs that it be more
> widely used -- it was never important in the last thirty years of its
> history, why should it be important now that Microsoft Word is so
> widely used?
Let those who need Word use it. To try to change emacs into something it
isn't is ignoring what makes it special.
Hal
------------------------------
Date: Mon, 18 Jun 2007 08:06:25 -0700
From: Ilias Lazaridis <ilias@lazaridis.com>
Subject: Re: Which Perl 5 OO extension can be seen as "standard" (defacto, quasi)?
Message-Id: <1182179185.478857.258380@p77g2000hsh.googlegroups.com>
On Jun 17, 11:21 pm, Michele Dondi <bik.m...@tiscalinet.it> wrote:
> On Sat, 16 Jun 2007 22:30:09 -0000, Ilias Lazaridis
>
> <i...@lazaridis.com> wrote:
> >I don't feel it gives me a "basic" or a "primitive' OO support (as I
[...] - (primitive etc.)
> >I summarize from your writings, the there is no OO extension available
> >which could be seen as a standard.
>
> >The build-in OO support of Perl5 is the today's standard.
>
> Yes, it is *the* one and only standard.
ok
> All of the available modules
> which give you bells and whistles build upon that. Talking about them,
> anyway... how 'bout Moose?!? (It is not meant as Perl-6-OO-model in
> Perl 5 but borrows heavily from the former.)
"Moose Perl 6 OO in Perl 5"
http://svn.pugscode.org/pugs/v6/docs/kp6-Notes.txt
> >That's fine for me personally (I alreay enjoy the freedom).
> Freedom is fine and all, but don't exaggerate. We recommand daily to
[...]
------------------------------
Date: Mon, 18 Jun 2007 08:12:06 -0700
From: Ilias Lazaridis <ilias@lazaridis.com>
Subject: Re: Which Perl 5 OO extension can be seen as "standard" (defacto, quasi)?
Message-Id: <1182179526.550886.159670@n2g2000hse.googlegroups.com>
On Jun 17, 5:54 pm, Emmanuel Florac <eflo...@imaginet.fr> wrote:
> Le Sat, 16 Jun 2007 22:30:09 +0000, Ilias Lazaridis a =E9crit :
>
> > Is there possibly an community agreement on a standard accessor- extens=
ion
> > (e.g. "
> > if you have to use automated accessor generation, use CPAN::???)
>
> I don't know for the accessors specifically, but Moose really blows
> everything else away IMHO.
* http://search.cpan.org/~stevan/Moose/
* http://search.cpan.org/~stevan/Class-MOP/ Class::MOP
I dislike the verbosity:
has 'x' =3D> (is =3D> 'rw', isa =3D> 'Int');
has 'y' =3D> (is =3D> 'rw', isa =3D> 'Int');
sub clear {
my $self =3D shift;
$self->x(0);
$self->y(0);
}
But the main question is again:
* how is the adoption of MOP/MOOSE?
* how much are the efforts synchronized with the original perl 6 OO
implementation?
.
--
http://dev.lazaridis.com/lang/ticket/2
------------------------------
Date: Mon, 18 Jun 2007 14:49:21 +0200
From: Reinhard Pagitsch <rprp@gmx.net>
Subject: Re: Win32: How to quit perl script during log off automatically ?
Message-Id: <46767f52$0$90271$14726298@news.sunsite.dk>
Peter Sobisch wrote:
> Reinhard Pagitsch <rprp@gmx.net> schrieb:
>> Peter Sobisch wrote:
>>> Reinhard Pagitsch <rprp@gmx.net> schrieb:
>>>>>>> Every time I try to shutdown or log off, pop-up is comming up with
>>>>>>> "application doesn't response" and expecting to kill by clicking a
>>>>>>> button -> very dirty thing :-/
>>>>>>> So, I tried to catch WM_QUERYENDSESSION (using Win32::GUI::Hook), but no
>>>>>> You should reveive a WM_CLOSE according to Bill.
>>>>> not really, I'm affraid windows doesn't sent neither WM_CLOSE nor
>>>>> WM_QUIT because of the same reason of not sending WM_QUERYENDSESSION.
>>>>
>>>> Have you also read the MSDN documentation about SetConsoleCtrlHandler?
>>>> The last paragraph say:
>>>>
>>>> The system generates CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, and
>>>> CTRL_SHUTDOWN_EVENT signals when the user closes the console, logs off,
>>>> or shuts down the system so that the process has an opportunity to clean
>>>> up before termination. Console functions, or any C run-time functions
>>>> that call console functions, may not work reliably during processing of
>>>> any of the three signals mentioned previously. The reason is that some
>>>> or all of the internal console cleanup routines may have been called
>>>> before executing the process signal handler.
>>>
>>> this is the thing I wanted to do but the Win32::API::Callback doesn't
>>> work :-(
>>> But I have a small workaround for now, I wrote a C module where I
>>> register a C-written-callback where I run ExitProcess().
>>> It's dirty to me, because I have no possibility to clean up or do
>>> something else, but, the process really ends on logoff.
>>>
>>> Neverthereless, I still interesting in Win32::API::Callback to get it
>>> work, because it would be very useful feature in Win32 enviroment.
>>>
>>> I tried to write something similars, but how I mentioned above, I've a
>>> problem to call a perl routine from the C-callback, not even the
>>> simplest one from perlcall manpage worked, I got SEGFAULT every time.
>>>
>>> I'm not sure, but could it be a problem calling the call_pv() or call_sv()
>>> from the callback which is launching in another thread ?
>>>
>>> [...]
>>>
>>>> Can you send me the code you are using, maybe I can find it out why the
>>>> Win32::API::Callback Module crashes.
>>>
>>> just a simple define of a callback:
>>>
>>> ----snip---
>>> use Win32::API;
>>> use Win32::API::Callback;
>>>
>>> my $callback = Win32::API::Callback->new(
>>> sub { my($a, $b) = @_; return $a+$b; },
>>> "NN", "N",
>>> );
>>> ----snap---
>>>
>>> gives the SEGFAULT and following message written to the console:
>>> "Free to wrong pool 15e2660 not e58b2660, <DATA> line 164."
>>>
>>
>> As Thomas wrote, the Module is broken. I assume to remove it and install
>> it again. In my environment, Activestate 5.8.8 on XP Sp2, this code
>> works perfect.
>>
>> You can download it from http://www.bribes.org/perl/ppm/ (30-Jan-2007)
>> or Activestate.
>>
>> Here you can find a list of PPM repositories:
>> http://win32.perl.org/wiki/index.php?title=PPM_Repositories
>>
>
> thanks for the link !
> Module doesn't crash anymore :-)
> now I only one step further, but the call I wanted to do fails now
> in calling the callback, here the code:
>
> ------------------------snip-----------------
> use strict;
> use Win32::API;
> use Win32::API::Callback;
>
> sub handler {
> my $type = shift;
> print "RECEIVED SIGNAL: $type\n",;
> return 1;
> }
>
> my $callback =
> Win32::API::Callback->new(\&handler, "I", "I" );
> my $function =
> Win32::API->new('kernel32','SetConsoleCtrlHandler','KI','I');
> $function->Call($callback,1);
>
> my $i= 0;
> while ($i<2000) {
> print ++$i,"\n";
> sleep(1); # in this loop press Ctrl+C
> }
> -----------------------snap----------------------
>
> it crashs now not by defining the callback but
> after I press "Ctrl+C" inside the loop :-/
Hmm in my case it does not crash but do also nothing. The print in the
handler sub will not be executed. Could it be that if have to do with
threads?
>
> If I do this in XSUB it seems to work, but only to do ExitProcess(),
> But I'd like to be able to call a callback.
>
> For comparison here comes my working XS code (with ExitProcess()):
>
> -----------snip------------------
> #include "EXTERN.h"
> #include "perl.h"
> #include "XSUB.h"
> #include "ppport.h"
> #include "windows.h"
> #include "wincon.h"
>
> #define MAX_EVENT CTRL_SHUTDOWN_EVENT
> int event[7] = { 0,0,0,0,0,0,0 };
>
> BOOL WINAPI CtrlHandler(DWORD type) {
> printf("received: %d\n",type);
> if (type > MAX_EVENT)
> return FALSE;
> if (event[type])
> ExitProcess(0);
> return FALSE;
> }
>
> MODULE = Logoff PACKAGE = Logoff
>
> int
> LogoffOnEvent(ev, logoff)
> int ev
> int logoff
> CODE:
> int rv;
> if (ev > MAX_EVENT) {
> rv = -1;
> } else {
> event[ev] = logoff;
> rv = SetConsoleCtrlHandler(CtrlHandler,TRUE);
> }
> RETVAL = rv;
> OUTPUT:
> RETVAL
> -----------snap------------------
>
> to test this module I use this simple piece of perl code:
>
> -----------snip-----------------
> use Logoff;
> Logoff::LogoffOnEvent(5,1); # quits after Logoff
> Logoff::LogoffOnEvent(0,1); # quits after Ctrl+C
>
> do {
> print "sleeping...$i\n"; # try to logoff or Ctrl+C
> sleep(1);
> } until $i > 10000;
> ------------snap----------------
>
> the big disadvantage of this is that I have no possibility to clean up
> my perl code.
Why not? You call the XS function direct, but if you do it via a .pm
than you can pass to the method a callback function which have to
executed before the XS code, theoretical.
>
> As I wrote before, I tried already to call a perl callback in
> CtrlHandler using call_sv() or call_pv(), without any success,
> this ends every time with segfault calling the perl code,
> the same thing as the perl variant using Win32::API::Callback
> also does (ofcourse after I re-installed the Win32::API-0.46
> module from http://www.bribes.org/perl/ppm/).
>
> Are there a more restrictions inside a CtrlHandler which disallow to
> do something like call a perl callback ?
>
regards,
Reinhard
--
PM Mails an rpirpag <at> gmx dot at
------------------------------
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 531
**************************************