[29290] in Perl-Users-Digest
Perl-Users Digest, Issue: 534 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 19 11:10:01 2007
Date: Tue, 19 Jun 2007 08: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, 19 Jun 2007 Volume: 11 Number: 534
Today's topics:
Re: For Loop <baxter.brad@gmail.com>
How to assign a Hash - newbie <evillen@gmail.com>
Re: How to assign a Hash - newbie anno4000@radom.zrz.tu-berlin.de
Re: How to assign a Hash - newbie <muede73@gmx.de>
Re: How to assign a Hash - newbie <paduille.4061.mumia.w+nospam@earthlink.net>
Re: How to assign a Hash - newbie <matteo_vitturi@virgilio.it>
Re: How to assign a Hash - newbie <evillen@gmail.com>
Re: How to assign a Hash - newbie <matteo_vitturi@virgilio.it>
Re: How to assign a Hash - newbie <evillen@gmail.com>
Re: How to test weather something is a func,method or v <muede73@gmx.de>
Re: How to test weather something is a func,method or v anno4000@radom.zrz.tu-berlin.de
Re: How to test weather something is a func,method or v <muede73@gmx.de>
package filename mismatches ? <bugbear@trim_papermule.co.uk_trim>
Passing hash to another script via commandline <blah@blahblah.co.uk>
Re: Passing hash to another script via commandline <jurgenex@hotmail.com>
Re: Passing hash to another script via commandline <blah@blahblah.co.uk>
Re: Passing hash to another script via commandline <matteo_vitturi@virgilio.it>
Re: Passing literal with reference? <baxter.brad@gmail.com>
Re: perl and php <stoupa@practisoft.cz>
Re: The Modernization of Emacs <harry.g.george@boeing.com>
Re: The Modernization of Emacs <dak@gnu.org>
Re: The Modernization of Emacs <mkb@incubus.de>
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: Tue, 19 Jun 2007 13:32:00 -0000
From: Brad Baxter <baxter.brad@gmail.com>
Subject: Re: For Loop
Message-Id: <1182259920.435082.63670@q69g2000hsb.googlegroups.com>
On Jun 19, 2:19 am, "Skye Shaw!@#$" <skye.s...@gmail.com> wrote:
> On Jun 17, 5:51 am, shapper <mdmo...@gmail.com> wrote:
>
> > Hello,
>
> > I don't know PERL and I need to convert a simple code to C# or VB.NET.
>
> I'm sorry
>
> > Could someone, please, help me with the conversion?
> > A description of how the loop works would be enough.
> > for $row (1..$h)
> > { for ($s=0,$i=$row; $s<$c; $i+=($h+($s<$rm)), ++$s)
> > { printf "%7u", $i }
> > print "\n";
>
> > }
>
> > ++$h;
> > for ($s=0,$i=$h; $s < $rm; $i+=$h, ++$s)
> > { printf "%7u", $i }
>
> for $row (1..$h)
> For Row=1 To H 'VB
> for( int row=1; row<h; row++ ) //C#
>
> printf "%7u", $i
> Console.WriteLine("{0:D7}",i) //.NoT
for( int row=1; row<=h; row++ ) //C#
--
Brad
------------------------------
Date: Tue, 19 Jun 2007 11:25:16 -0000
From: "evillen@gmail.com" <evillen@gmail.com>
Subject: How to assign a Hash - newbie
Message-Id: <1182252316.141926.122800@q75g2000hsh.googlegroups.com>
Hi
Is there a more elegant to assign one hash to another - the solution
below works:
my $table = 'c';
my %dbitems;
if($table eq 'a'){%dbitems = %a}
elsif($table eq 'b'){%dbitems = %b}
elsif($table eq 'c'){%dbitems = %c}
elsif($table eq 'd'){%dbitems = %d}
elsif($table eq 'e'){%dbitems = %e}
elsif($table eq 'f'){%dbitems = %f}
elsif($table eq 'g'){%dbitems = %g}
but I hoped something like this would achieve the same:
my $table = 'c';
my %dbitems = %.$table;
I've tried variations but I get syntax errors such as:
"Can't use string ("c") as a HASH ref while "strict refs"" or "Only
hard references are allowed by "strict refs""
Thanks for any help
NJH
------------------------------
Date: 19 Jun 2007 11:46:57 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: How to assign a Hash - newbie
Message-Id: <5dpu1hF33dnopU1@mid.dfncis.de>
evillen@gmail.com <evillen@gmail.com> wrote in comp.lang.perl.misc:
> Hi
>
> Is there a more elegant to assign one hash to another - the solution
> below works:
>
> my $table = 'c';
> my %dbitems;
>
> if($table eq 'a'){%dbitems = %a}
> elsif($table eq 'b'){%dbitems = %b}
> elsif($table eq 'c'){%dbitems = %c}
> elsif($table eq 'd'){%dbitems = %d}
> elsif($table eq 'e'){%dbitems = %e}
> elsif($table eq 'f'){%dbitems = %f}
> elsif($table eq 'g'){%dbitems = %g}
>
> but I hoped something like this would achieve the same:
>
> my $table = 'c';
> my %dbitems = %.$table;
You need an auxiliary hash (%sel below) to do that in a sane manner.
Untested:
my %sel;
@sel{ 'a' .. 'g'} = \ ( %a, %b, %c, %d, %e, %f, %g);
my $table = 'c';
my %dbitems = %{ $sel{ $table} };
You may be able to work with the hashrefs from %sel directly, without
copying the hash to %dbitems:
my $dbitems = $sel{ $table};
...and then use "$dbitems->{ $key}" instead of "$dbitems{ $key}".
Anno
------------------------------
Date: Tue, 19 Jun 2007 14:07:37 +0200
From: muede <muede73@gmx.de>
Subject: Re: How to assign a Hash - newbie
Message-Id: <1182254873.726088@arno.fh-trier.de>
Hi, I am newbie to perl as well.
> my $table = 'c';
> my %dbitems = %.$table;
You are trying to concat a non string -> %.
my %dbitems = '%'.$table;
would result in a scalar ( string ) on the right side.
my %dbitems = eval('%'.$table);
Would work I guess.
But depending on what you are doing , you might want to use references:
my $table = \%c;
my %dbitems = %{$table};
-ap
------------------------------
Date: Tue, 19 Jun 2007 12:28:24 GMT
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: How to assign a Hash - newbie
Message-Id: <IZPdi.2767$ZY1.948@newsread2.news.pas.earthlink.net>
On 06/19/2007 06:25 AM, evillen@gmail.com wrote:
> Hi
>
> Is there a more elegant to assign one hash to another - the solution
> below works:
>
> my $table = 'c';
> my %dbitems;
>
> if($table eq 'a'){%dbitems = %a}
> elsif($table eq 'b'){%dbitems = %b}
> elsif($table eq 'c'){%dbitems = %c}
> elsif($table eq 'd'){%dbitems = %d}
> elsif($table eq 'e'){%dbitems = %e}
> elsif($table eq 'f'){%dbitems = %f}
> elsif($table eq 'g'){%dbitems = %g}
>
> but I hoped something like this would achieve the same:
>
> my $table = 'c';
> my %dbitems = %.$table;
>
> I've tried variations but I get syntax errors such as:
> "Can't use string ("c") as a HASH ref while "strict refs"" or "Only
> hard references are allowed by "strict refs""
>
> Thanks for any help
> NJH
>
Go into a command prompt and type
perldoc -q "variable as"
The Perl documentation on your system should explain this.
When you're done reading that, type "perldoc perlfaq"
------------------------------
Date: Tue, 19 Jun 2007 07:36:17 -0700
From: mattsteel <matteo_vitturi@virgilio.it>
Subject: Re: How to assign a Hash - newbie
Message-Id: <1182263777.918468.55730@m36g2000hse.googlegroups.com>
evillen@gmail.com ha scritto:
> Hi
>
> Is there a more elegant to assign one hash to another - the solution
> below works:
>
> my $table = 'c';
> my %dbitems;
>
> if($table eq 'a'){%dbitems = %a}
> elsif($table eq 'b'){%dbitems = %b}
> elsif($table eq 'c'){%dbitems = %c}
> elsif($table eq 'd'){%dbitems = %d}
> elsif($table eq 'e'){%dbitems = %e}
> elsif($table eq 'f'){%dbitems = %f}
> elsif($table eq 'g'){%dbitems = %g}
>
> but I hoped something like this would achieve the same:
>
> my $table = 'c';
> my %dbitems = %.$table;
>
> I've tried variations but I get syntax errors such as:
> "Can't use string ("c") as a HASH ref while "strict refs"" or "Only
> hard references are allowed by "strict refs""
>
> Thanks for any help
> NJH
Maybe this is what you want.
my $table = 'c';
my %dbitems;
eval "\%dbitems = \%$table";
M.
------------------------------
Date: Tue, 19 Jun 2007 14:46:26 -0000
From: "evillen@gmail.com" <evillen@gmail.com>
Subject: Re: How to assign a Hash - newbie
Message-Id: <1182264386.568361.31900@o61g2000hsh.googlegroups.com>
anno4...@radom.zrz.tu-berlin.de wrote:
> evillen@gmail.com <evillen@gmail.com> wrote in comp.lang.perl.misc:
> > Hi
> >
> > Is there a more elegant to assign one hash to another - the solution
> > below works:
> >
> > my $table = 'c';
> > my %dbitems;
> >
> > if($table eq 'a'){%dbitems = %a}
> > elsif($table eq 'b'){%dbitems = %b}
> > elsif($table eq 'c'){%dbitems = %c}
> > elsif($table eq 'd'){%dbitems = %d}
> > elsif($table eq 'e'){%dbitems = %e}
> > elsif($table eq 'f'){%dbitems = %f}
> > elsif($table eq 'g'){%dbitems = %g}
> >
> > but I hoped something like this would achieve the same:
> >
> > my $table = 'c';
> > my %dbitems = %.$table;
>
> You need an auxiliary hash (%sel below) to do that in a sane manner.
> Untested:
>
> my %sel;
> @sel{ 'a' .. 'g'} = \ ( %a, %b, %c, %d, %e, %f, %g);
>
> my $table = 'c';
> my %dbitems = %{ $sel{ $table} };
>
> You may be able to work with the hashrefs from %sel directly, without
> copying the hash to %dbitems:
>
> my $dbitems = $sel{ $table};
>
> ...and then use "$dbitems->{ $key}" instead of "$dbitems{ $key}".
>
> Anno
Thanks guys, however I was advised to try using a HOH - so now I am
trying this code:
#START
#!c:/perl/bin/perl.exe -w
use strict;
use diagnostics;
#-------------------------------------------------
#Description of hashes is: fieldname[label,length,category,tick,order]
my %HoH = (
names => {
fore => ['Frank','Alex','Wayne'],
sur => ['Lampard','Ferguson','Rooney'],
},
places => {
north => ['Burnley', 'Chester', 'Doncaster'],
south => ['Brighton', 'Cheltenham', 'Dover'],
},
);
my $table = "names";
my %Hash = $HoH{$table};
print "My \%Hash is: ", %Hash;
#END
however this won't assign a Hash to Hash as expected. How do I assign
the name/value pairs of "names" to %Hash?
NJH
------------------------------
Date: Tue, 19 Jun 2007 07:53:57 -0700
From: mattsteel <matteo_vitturi@virgilio.it>
Subject: Re: How to assign a Hash - newbie
Message-Id: <1182264837.534725.47680@o61g2000hsh.googlegroups.com>
>
> my $table = "names";
> my %Hash = $HoH{$table};
>
> print "My \%Hash is: ", %Hash;
>
> #END
>
> however this won't assign a Hash to Hash as expected. How do I assign
> the name/value pairs of "names" to %Hash?
>
> NJH
my %Hash = %{$HoH{$table}}
------------------------------
Date: Tue, 19 Jun 2007 14:58:17 -0000
From: "evillen@gmail.com" <evillen@gmail.com>
Subject: Re: How to assign a Hash - newbie
Message-Id: <1182265097.024025.252240@n2g2000hse.googlegroups.com>
On 19 Jun, 15:53, mattsteel <matteo_vitt...@virgilio.it> wrote:
> > my $table = "names";
> > my %Hash = $HoH{$table};
>
> > print "My \%Hash is: ", %Hash;
>
> > #END
>
> > however this won't assign a Hash to Hash as expected. How do I assign
> > the name/value pairs of "names" to %Hash?
>
> > NJH
>
> my %Hash = %{$HoH{$table}}
Many thanks Matt - it's been a long day....
------------------------------
Date: Tue, 19 Jun 2007 13:57:23 +0200
From: muede <muede73@gmx.de>
Subject: Re: How to test weather something is a func,method or var
Message-Id: <1182254259.194651@arno.fh-trier.de>
Thanks for the input.
The way I see it now, this would work to distinguish
@Foo::var1 and $Foo::var2 from &Foo::func3.
But I guess there is no such straight way for telling if
something is a
Foo->method or
Foo::func,
because it is just a matter of how the programmer of the module wanted
these to be used. To perl they are just CODE or subs. All that the
operator '->' does is adding the module name to the argument list.
I would have to look at the code.Right ?
-ap
------------------------------
Date: 19 Jun 2007 12:22:27 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: How to test weather something is a func,method or var
Message-Id: <5dq043F3648aaU1@mid.dfncis.de>
muede <muede73@gmx.de> wrote in comp.lang.perl.misc:
> Thanks for the input.
What input? Please quote references and relevant parts of the
message you're replying to.
[...]
> But I guess there is no such straight way for telling if
> something is a
> Foo->method or
> Foo::func,
>
> because it is just a matter of how the programmer of the module wanted
> these to be used. To perl they are just CODE or subs. All that the
> operator '->' does is adding the module name to the argument list.
> I would have to look at the code.Right ?
The code doesn't tell you (reliably) whether a sub was meant to be
called as a method. In fact, there are subs that can be called both
ways. Only the documentation can tell you that.
Anno
------------------------------
Date: Tue, 19 Jun 2007 14:46:37 +0200
From: muede <muede73@gmx.de>
Subject: Re: How to test weather something is a func,method or var
Message-Id: <1182257213.515483@arno.fh-trier.de>
anno4000@radom.zrz.tu-berlin.de wrote:
> muede <muede73@gmx.de> wrote in comp.lang.perl.misc:
>
>> Thanks for the input
>
, to everyone who replied to my question.
>
> The code doesn't tell you (reliably) whether a sub was meant to be
> called as a method. In fact, there are subs that can be called both
> ways. Only the documentation can tell you that.
>
Thanks for the input.
-ap
------------------------------
Date: Tue, 19 Jun 2007 14:38:29 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: package filename mismatches ?
Message-Id: <4677dc55$0$8756$ed2619ec@ptn-nntp-reader02.plus.net>
I've often made the mistake of getting the
package name "wrong" when making a module.
Commonly, when I make a file Utils/Edit.pm
(intended to be used via use Utils::Edit;)
I have a good chance of putting
package Edit;
In the code.
Now I understand that "use blah"
is equivalent to:
BEGIN { require Module; import Module LIST; }
Is there a way to make the import fail
if the package has not supplied it,
so that if I've made my usual bone head mistake,
perl will tell me?
BugBear
------------------------------
Date: Tue, 19 Jun 2007 14:57:41 +0100
From: "IanW" <blah@blahblah.co.uk>
Subject: Passing hash to another script via commandline
Message-Id: <f58nbp$muc$1$8300dec7@news.demon.co.uk>
Hi
How do I pass a hash to another script via the command line?
That is, if I do this
use strict;
my %data = (
field1 => 'f1val',
field2 => 'f2val'
);
my $result = `perl z:/interface.pl \%data`;
and in interface.pl I have the lines:
use strict;
my($dataref) = $ARGV[0];
print $dataref->{'field1'};
I get the error:
Can't use string ("%data") as a HASH ref while "strict refs" in use at
z:/interface.pl line ..
and if I comment out "use strict" then I get nothing.
What am I doing wrong?
Thanks
Ian
------------------------------
Date: Tue, 19 Jun 2007 14:05:43 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Passing hash to another script via commandline
Message-Id: <XoRdi.7443$u65.1117@trndny07>
IanW wrote:
> How do I pass a hash to another script via the command line?
[sample script snipped, thank you for providing it]
> What am I doing wrong?
The shell command line argument interface does not provide any means to pass
complex data structures like hashes or references. It can deal with simple
strings only. This is not a limitation of Perl but of the command shell.
In other words: you need to pass the actual keys and values of your hash (as
strings!) and then recompose them into a hash in the called program.
It might be easier to use Data::Dumper to convert the hash into a textual
representation that can readily loaded into perl again or to use some other
form of interprocess communication.
jue
------------------------------
Date: Tue, 19 Jun 2007 15:06:30 +0100
From: "IanW" <blah@blahblah.co.uk>
Subject: Re: Passing hash to another script via commandline
Message-Id: <f58ns7$8om$1$8302bc10@news.demon.co.uk>
"IanW" <blah@blahblah.co.uk> wrote in message
news:f58nbp$muc$1$8300dec7@news.demon.co.uk...
>
> and if I comment out "use strict" then I get nothing.
>
> What am I doing wrong?
I should say I am doing a "print $result;" in the calling script!
------------------------------
Date: Tue, 19 Jun 2007 07:23:52 -0700
From: mattsteel <matteo_vitturi@virgilio.it>
Subject: Re: Passing hash to another script via commandline
Message-Id: <1182263032.600752.186580@q69g2000hsb.googlegroups.com>
IanW ha scritto:
> Hi
>
> How do I pass a hash to another script via the command line?
>
You can't.
> What am I doing wrong?
>
> Thanks
> Ian
Possible workaround: you can try to tie-untie your hash to a file so
you can pass the filename to the second script which can tie-untie the
same hash, then.
------------------------------
Date: Tue, 19 Jun 2007 13:55:44 -0000
From: Brad Baxter <baxter.brad@gmail.com>
Subject: Re: Passing literal with reference?
Message-Id: <1182261344.633690.44570@k79g2000hse.googlegroups.com>
On Jun 18, 12:14 am, Uri Guttman <u...@stemsystems.com> wrote:
> >>>>> "BB" == Brad Baxter <baxter.b...@gmail.com> writes:
>
> BB> It is unlikely that he is planning to pass a 316 MB literal.
> BB> So I say again, just pass the darn thing. I will go out on
> BB> a limb and venture to say that the number of times a scalar
> BB> is passed to a subroutine vs. the number of times a reference
> BB> to a scalar is passed is about, oh, 1_000_000_000:1
>
> BB> Give or take.
>
> ever realize that perl objects are references and are always passed to
> methods? i think that evens out the ratio a bit. and it isn't how often
> a scalar is passed around but how often large ones are passed. in one
> system of mine, i generally pass around scalar refs since that data may
> get copied from @_ and passed around even more. it makes sense to pass
> scalar refs then to keep the copying overhead to a minumum.
Yes, I do realize that about objects, and I expected someone to
mention it.
However, I suspect that many more of those are references to hashes,
arrays
or whatnot than are references to scalars, so I don't really think it
evens
out the ratio much. (The "ratio" being, of course a figment for
expression
purposes. :-)) I don't doubt for a minute that many people pass
references
to scalars when it makes sense to do so. But I still believe that far
and
away, simple scalars are passed more than anything else. I didn't
think it
was that debatable. :-) In particular, when was the last time
(outside of
this thread) that you saw someone pass a literal as \"Hello, world?"
--
Brad
------------------------------
Date: Tue, 19 Jun 2007 11:57:07 +0200
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: perl and php
Message-Id: <f589bd$6ad$1@ns.felk.cvut.cz>
skywriter14 wrote:
> On Jun 18, 12:30 pm, Bart Lateur <bart.lat...@pandora.be> wrote:
>> Only for small sites/pages.
>>
>> --
>> Bart.
>
> Please tell me why there are tons of web sites made with PHP as
> compared to Perl or any other language, if PHP is worse than Perl and
> Ruby. How does it survive? Not only the rookies program with PHP,
> isn't it?
>
One reason is that Perl is more dangerous for webhosting server when
webhosting company do not have virtual servers created on server. In other
word bone-lazy company install PHP, don't allow Perl for customers and make
money without security hazard. Serious company must make more work to allow
Perl for customers without security hazard.
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
------------------------------
Date: Tue, 19 Jun 2007 05:14:38 GMT
From: Harry George <harry.g.george@boeing.com>
Subject: Re: The Modernization of Emacs
Message-Id: <xqxps3swmo1.fsf@cola3.ca.boeing.com>
Galen Boyer <galen_boyer@yahoo.com> writes:
> On Mon, 18 Jun 2007, jadamson@partners.org wrote:
>
> > 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.
>
> Emacs will always be for people who like to be able to constantly fiddle
> with their environments which continues to increase the efficiency with
> which they perform their tasks, increasing the # of tasks they can
> perform and therefore increasing the # of peers it would take to equal
> the amount of work they alone perform. Most other environments will be
> for those just trying to perform their tasks and staying even with the
> average proficiency chart.
>
> --
> Galen Boyer
"constantly fiddle"
I've used emacs since the 1980's. I've used it for text, xml, html
markups, programming in many languages, and natural languages. In a
few cases I've "fiddled" with the environment. I've even written a
"mode". But it has never been "constantly". One does the setup, and
then uses it day after day, year after year... until you have a new
need, in which case you re-tune your settings and then go back to
work.
"trying to perform their tasks...average proficiency"
Aye, there's the rub. As Fred Brooks and others repeatedly point out,
there is little room in programming for average proficiency.
I don't mind folks using any editor they want, as long as they are
proficient. In those cases, I have no problem doing Extreme
Programming with them -- code a bit, save, the other guy codes a bit.
But when someone uses vi and then forgets how to do block moves, or
uses eclipse and bogs down the session, or uses MS Notepad and can't
enforce language-specific indents, I get frustrated.
--
Harry George
PLM Engineering Architecture
------------------------------
Date: Tue, 19 Jun 2007 15:53:21 +0200
From: David Kastrup <dak@gnu.org>
Subject: Re: The Modernization of Emacs
Message-Id: <861wg8rqy6.fsf@lola.quinscape.zz>
Harry George <harry.g.george@boeing.com> writes:
> I don't mind folks using any editor they want, as long as they are
> proficient. In those cases, I have no problem doing Extreme
> Programming with them -- code a bit, save, the other guy codes a
> bit. But when someone uses vi and then forgets how to do block
> moves, or uses eclipse and bogs down the session, or uses MS Notepad
> and can't enforce language-specific indents, I get frustrated.
My favorite killing offence is /* vi:set ts=4: */.
--
David Kastrup
------------------------------
Date: Tue, 19 Jun 2007 16:30:09 +0200
From: Matthias Buelow <mkb@incubus.de>
Subject: Re: The Modernization of Emacs
Message-Id: <5dq7j6F33s1anU1@mid.dfncis.de>
David Kastrup wrote:
> My favorite killing offence is /* vi:set ts=4: */.
This is apparently the default setting in many of the so-called "IDE"s
today.. I think it's another unwelcome poison gift from the ignorant
M$FT world (I suspect some primitive Windoze IDE which couldn't
differentiate between TAB and indent probably offered the programmer
changing the tabwidth as the only method for changing indentation, and
then this method got stuck...)
F'up to comp.emacs.
------------------------------
Date: Tue, 19 Jun 2007 12:37:44 +0200
From: Reinhard Pagitsch <rprp@gmx.net>
Subject: Re: Win32: How to quit perl script during log off automatically ?
Message-Id: <4677b1f9$0$90273$14726298@news.sunsite.dk>
Peter Sobisch wrote:
> Reinhard Pagitsch <rprp@gmx.net> schrieb:
>>>> [...]
>>>> 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?
>
> it should at least print the numbers, because it is regular perl code,
> thats strange...
>
>>> 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.
>
> the call of Logoff::LogoffOnEvent() is not the problem, this registers only
> a C-routine as a callback, which is called later (on event).
> This doesn't make any difference.
>
> What I need here is: how to call a perl routine from the CtrlHandler()
> in XS. There are several API calls to do this: (perl_)call_pv,
> (perl_)call_sv and so on. But none of them seems to run in this
> callback.
Can you try to ask in perl.xs news group? In the libwin32-0.191 and also
in Win32-API-0.46 module I can see that call_pv have to work, but I have
not the time to find out how to make it working in your XS.
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 534
**************************************