[25620] in Perl-Users-Digest
Perl-Users Digest, Issue: 7863 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 7 09:05:38 2005
Date: Mon, 7 Mar 2005 06:05:18 -0800 (PST)
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, 7 Mar 2005 Volume: 10 Number: 7863
Today's topics:
Re: beta testing <1usa@llenroc.ude.invalid>
Re: beta testing <1usa@llenroc.ude.invalid>
convert gb18030 to utf16 <xah@xahlee.org>
Re: convert gb18030 to utf16 <william@wilbur.25thandClement.com>
Re: convert gb18030 to utf16 <xah@xahlee.org>
Re: cperl-mode and emacs-21.4 brocken? (David Combs)
Re: Drag and drop <chamynpj@___brightonline.com.au>
Re: Drag and drop <1usa@llenroc.ude.invalid>
Re: goto &Package::func destroying @_?! <not@invalid.invalid>
Re: goto &Package::func destroying @_?! <not@invalid.invalid>
Re: print isn't flashed using PERL by MSWin32 on Window <newspost@kohombanDELETE.net>
Re: SOAP::Lite +wsdl <vek@station02.ohout.pharmapartners.nl>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 06 Mar 2005 22:29:18 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: beta testing
Message-Id: <Xns9611B1E838F18asu1cornelledu@127.0.0.1>
"robin" <robin@infusedlight.net> wrote in news:1110087761.522984.103340
@f14g2000cwb.googlegroups.com:
> if anyone is interested in beta testing this,
Robin, you could try to learn Perl in your free time, rather than coming
up with crap like this.
> www.infusedlight.net/cgi-bin/bbs.pl - please report bugs
Well, the whole script is one colossal bug.
I especially found:
$key = "$userparam$string$about$string$nick$string$aim$string$icq$string
$hobbies$string$favoritethings$string$webtitle$string${websiteaddress}
private\n" if $privateparam;
No wonder you have spelling errors sprinkled at various points in the
scripts. Who has the ocular dexterity to decipher this?
Sinan.
------------------------------
Date: Sun, 06 Mar 2005 22:44:42 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: beta testing
Message-Id: <Xns9611B4846ACC8asu1cornelledu@127.0.0.1>
"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in
news:Xns9611B1E838F18asu1cornelledu@127.0.0.1:
> "robin" <robin@infusedlight.net> wrote in
news:1110087761.522984.103340
> @f14g2000cwb.googlegroups.com:
...
> Well, the whole script is one colossal bug.
>
> I especially found:
>
> $key =
...
I am sorry, I did a partial paste. Here is the interesting bit from
bbs.pl:
if ($psplit2[0] eq $userparam)
{
$key = "$userparam$string$about$string$nick$string$aim$string$icq
$string$hobbies$string$favoritethings$string$webtitle$string
${websiteaddress}private\n" if $privateparam;
$key="$userparam$string$about$string$nick$string$aim$string$icq
$string$hobbies$string$favoritethings$string$webtitle$string
${websiteaddress}\n" if ! $privateparam;
}
Please do not attempt to explain this as the explanation might be even
more painful than looking at the actual code.
No wonder you have spelling errors sprinkled at various points in the
scripts. Who has the ocular dexterity to decipher this?
A couple of recommendations:
* Look into the CGI::Application module (or any of its descendants).
* For my elementary needs, I have found CGI::Application coupled with
CGI::Application::Session, Class::DBI (w/ sqlite) and HTML::Template to
be a wonderful combination.
* And, I cannot stress this enough, please do consider thinking before
programming.
* Do read the documentation for the modules you are using.
* Your code is sprinkled with crap like this:
my $hobbies = param ('fivehobbies');
$hobbies =~ s/>/&gt;/gm;
$hobbies =~ s/</&lt;/gm;
$hobbies =~ s/>/>/mg;
$hobbies =~ s/</</mg;
WTF? Use the HTML::Entities module:
#! /usr/bin/perl
use CGI;
use HTML::Entities;
my $cgi = CGI->new;
if(defined (my $value = $cgi->param('value'))) {
print $cgi->header, encode_entities($value);
} else {
print $cgi->header, <<HTML
<html>
<body>
<form>
<input type="text" size="20" name="value">
<input type="submit">
</form>
</body>
</html>
HTML
;
}
__END__
Sinan.
------------------------------
Date: 6 Mar 2005 16:17:43 -0800
From: "Xah Lee" <xah@xahlee.org>
Subject: convert gb18030 to utf16
Message-Id: <1110154663.783487.150670@l41g2000cwc.googlegroups.com>
i have a bunch of files encoded in GB18030. Is there a way to convert
them to utf16?
Xah
x...@xahlee.org
http://xahlee.org/PageTwo_dir/ more.html
------------------------------
Date: Sun, 6 Mar 2005 20:00:02 -0800
From: William Ahern <william@wilbur.25thandClement.com>
Subject: Re: convert gb18030 to utf16
Message-Id: <270tf2-sps.ln1@wilbur.25thandClement.com>
Xah Lee <xah@xahlee.org> wrote:
> i have a bunch of files encoded in GB18030. Is there a way to convert
> them to utf16?
The process would go roughly like so
use Encode qw/encode decode/;
open FILE, '</path/to/gb18030/file' or die "open: $!";
$\ = undef;
my $utf8 = decode('gb18030',<FILE>);
my $ucs2 = encode('UCS-2BE', $utf8);
If this is going to be a regular process, you should wrap that in an eval{}
because the Encode routines like to call die, regardless of whether you pass
in options like Encode::FB_DEFAULT or Encode::FB_QUIET.
------------------------------
Date: 7 Mar 2005 05:40:37 -0800
From: "Xah Lee" <xah@xahlee.org>
Subject: Re: convert gb18030 to utf16
Message-Id: <1110202837.479260.3360@o13g2000cwo.googlegroups.com>
Can you tell me when did this module became part of Perl? (what
version)
(i haven't been active in Perl since 2004)
Thanks.
Xah
xah@xahlee.org
http://xahlee.org/PageTwo_dir/more.html
William Ahern wrote:
> Xah Lee <xah@xahlee.org> wrote:
> > i have a bunch of files encoded in GB18030. Is there a way to
convert
> > them to utf16?
>
> The process would go roughly like so
>
> use Encode qw/encode decode/;
>
> open FILE, '</path/to/gb18030/file' or die "open: $!";
>
> $\ = undef;
>
> my $utf8 = decode('gb18030',<FILE>);
> my $ucs2 = encode('UCS-2BE', $utf8);
>
> If this is going to be a regular process, you should wrap that in an
eval{}
> because the Encode routines like to call die, regardless of whether
you pass
> in options like Encode::FB_DEFAULT or Encode::FB_QUIET.
------------------------------
Date: Mon, 7 Mar 2005 03:21:08 +0000 (UTC)
From: dkcombs@panix.com (David Combs)
Subject: Re: cperl-mode and emacs-21.4 brocken?
Message-Id: <d0ghb3$4pa$1@reader1.panix.com>
In article <cvb777$2h72$1@agate.berkeley.edu>,
Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
>
>The "mine" and "their" versions have the same "version number"; *this*
>is the problem I had in mind. (*If* "their" version has any version
>number at all - they have some opposition to RCS strings in .el files...)
>
>Yours,
>Ilya
PLEASE, Ilya, prevail on the (gnu-?)emacs preparers/bundlers to
place in:
(1) "their" cperl-mode
(2) the release-notes
(3) the emacs manual (and .info)
this:
A *LOUD* notice that "their" cperl-mode is a hacked-by-them
*version* of *your* cperl-mode.
How "theirs" and yours differ, and why.
Where to get *yours* -- and either why some
(many) people prefer yours, or the url
of that opinion.
Ilya -- being as cperl-mode is ***YOUR*** code (even if not "legally",
due to gnu-license?), you REQUIRE that they do the above.
(also, doesn't the gnu/fsf-"license" *require* that they
do this revealing of how to get the original, ie yours?)
Thanks (from us all?)
David
(and much! thanks, from us all, for creating cperl-mode!)
------------------------------
Date: Mon, 7 Mar 2005 21:27:16 +0800
From: "Tino" <chamynpj@___brightonline.com.au>
Subject: Re: Drag and drop
Message-Id: <d0hkre$pn9$1@news-02.connect.com.au>
"Fabian Pilkowski" <pilkowsk@informatik.uni-marburg.de> wrote in message
news:MPG.1c90be9c39b020a69898b9@news.individual.de...
>* Tino wrote:
>>
>> I would like to be able to drag and drop files onto a .pl file in the
>> same
>> way I can drop files onto a .bat file. I made a .bat which can do this
>> but
>> if I try to do the same thing with a .pl file I find the .pl file isn't
>> able
>> to accept files for drag and drop operations, the cursor changes to the
>> "not
>> allowed operation" symbol when the file being dropped is over the .pl
>> file.
>> What do I have to do to the .pl file to make it work like the .bat file?
>
> If you've a version of ActiveState's Perl installed have a look into its
> bin-directory. You will find a small tool named "pl2bat.bat" which wrap
> your perl code into a batch file.
>
> Otherwise you can add a new key to your windows registry to imitate the
> behavior of batch files. Then you can drag and drop your files directly
> to you perl script. Just create the key
>
> HKEY_CLASSES_ROOT\Perl\shellex\DropHandler\
>
> with default value set to "{86C86720-42A0-1069-A2E8-08002B30309D}".
> Don't ask something about this CLSID, for me this works on a german
> winxp machine. Perhaps you wanna compare this with your own system
> settings. I've copied this value from
>
> HKEY_CLASSES_ROOT\batfile\shellex\DropHandler\
>
> regards,
> fabian
Thanks. I tried both options and they both work so I will go with drag and
drop directly onto the Perl script. As per your example I used the
DropHandler value from "batfile". I wonder if there is a more appropriate
value for "Perl"?
------------------------------
Date: Mon, 07 Mar 2005 14:00:38 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Drag and drop
Message-Id: <Xns96125BAA7CCFCasu1cornelledu@127.0.0.1>
"Tino" <chamynpj@___brightonline.com.au> wrote in
news:d0hkre$pn9$1@news-02.connect.com.au:
>
> "Fabian Pilkowski" <pilkowsk@informatik.uni-marburg.de> wrote in
> message news:MPG.1c90be9c39b020a69898b9@news.individual.de...
...
>> Otherwise you can add a new key to your windows registry to imitate
>> the behavior of batch files. Then you can drag and drop your files
>> directly to you perl script. Just create the key
>>
>> HKEY_CLASSES_ROOT\Perl\shellex\DropHandler\
>>
>> with default value set to "{86C86720-42A0-1069-A2E8-08002B30309D}".
...
> Thanks. I tried both options and they both work so I will go with drag
> and drop directly onto the Perl script. As per your example I used the
> DropHandler value from "batfile". I wonder if there is a more
> appropriate value for "Perl"?
No. That is the excutable drag & drop handler. A quick look through the
registry would have shown you that that value is the same for exe, pif etc
files as well.
Sinan
------------------------------
Date: Mon, 07 Mar 2005 11:46:52 +1000
From: Matthew Braid <not@invalid.invalid>
Subject: Re: goto &Package::func destroying @_?!
Message-Id: <d0gbqc$1opq$1@bunyip2.cc.uq.edu.au>
Anno Siegel wrote:
> Matthew Braid <not@invalid.invalid> wrote in comp.lang.perl.misc:
>>Unfortunately this is another one that I can't reproduce in a small
>>script, but maybe the description will trigger something from someone....
>>
>>In the system I'm writing library functions can be extended like so:
>>
>>package Core;
>>use base qw/Exporter/;
>
> Why are you making Exporter a base class? You're not using it.
Hmm, good point - probably an artifact of development. In the original
code the 'Core' package uses another package as a base that has a custom
import function.
>>{
>> no strict 'refs';
>> sub import { # This code severely chopped down to basics
>> # Redefine import so that overrides are noticed even
>> # in places where the original function has already been
>> # imported
>> my $class = shift;
>> my @funcs = @_;
>> my ($caller) = caller();
>> for my $f (@funcs) {
>> *{"$caller\::$f"} = sub {goto &{"$class\::$f"}};
>
>
> A sub that does nothing but "goto &foo" is equivalent to foo. As given,
> you might as well say
>
> *{"$caller\::$f"} = \ &{"$class\::$f"};
Not quite. In my way, if "$class\::$f" is overridden later to a new
function, the new function will be called even in packages where
"$class\::$f" has _already been imported_. The code below demonstrates this:
# START CODE
{
package Foo;
sub test {
print "FOO!\n";
}
}
{
package Bar;
*Bar::test = \&Foo::test; # Standard import
sub bartest {
print "BAR!\n";
test();
}
}
{
package Woo;
# V---- My import - changes will be noticed
BEGIN {*Woo::test = sub { goto &Foo::test }}
sub wootest {
print "WOO!\n";
test();
}
}
*test = \&Foo::test;
*bartest = \&Bar::bartest;
*wootest = \&Woo::wootest;
test(); # CALL 1
bartest(); # CALL 2
wootest(); # CALL 3
*Foo::test = sub { print "NEW FOO!\n" };
test(); # CALL 4
bartest(); # CALL 5
wootest(); # CALL 6
# END CODE
Which results in (comments added):
FOO! # CALL 1
BAR! # CALL 2
FOO!
WOO! # CALL 3
FOO!
FOO! # CALL 4 - changes not noticed
BAR! # CALL 5
FOO! # Hasn't noticed Foo::test has changed!
WOO! # CALL 6
NEW FOO! # _Has_ noticed Foo::test has changed!
Of course, in my actual code there wouldn't be three names - 'bartest'
and 'wootest' would all be called 'test' so the main script doesn't need
to know the new function names. Not usually what you want (which is why
Exporter does it your way) but in my case it is.
>>sub foo {
>> print "Core::foo GOT (@_)\n";
>>}
>># --- In a file not so very far away...
>>package Extension;
>>BEGIN {
>> require Core;
>> my $old = \&Core::foo;
>> sub foo {
>> print "Ext::foo GOT (@_)\n";
>> goto &$old;
>> }
>> *Core::foo = \&foo;
>
> Here you are changing the package Core. Normally an importing module
> has no business doing that.
True, but as I said the importing module is acting as a plugin that is
_supposed_ to override the 'Core'. Its whole purpose is to do 'extra
stuff' without the main script needing to do anything different. So
rather than the main script needing to be changed for every plugin, all
it needs to do is 'eval "require $extension"' (with error checking and
whatnot) - and then extensions can be defined in a config file.
>>Of course, extensions can be extended etc etc. The problem I've run in
>>to is the goto bit - it seems that if the level of 'extension' is too
>
> Which goto? There is one in Core and one in Extension.
So far I've only run across this in the extensions. In the right
circumstances I guess the core goto's would also suffer the same effects
if it really is a problem with goto&.
>>high, the destination of the goto ends up with @_ full of undefs - right
>>number of args, wrong values.
>
> How high is too high? With your code the arguments are handed down
> just fine.
In my real code the level is 4 goto&'s. I know extending the test code I
posted does work - hence the first line of my post about it being one of
those annoying problems that I can't easily replicate. I spent a very
frustrating two hours trying to get it to happen in test code, and I
don't think my company would be too happy about me posting what is
technically their code to a newsgroup. It all boiled down to three
debugging lines:
print "EXT3: ABOUT TO GOTO EXT2::func - \@_ IS (@_)\n";
goto &Ext2::func;
#... in another package not so far away
package Ext2;
#....
sub func {
print "EXT2: ARRIVED AT EXT2::func - \@_ IS (@_)\n";
my ($href, @otherstuff) = @_;
print "EXT2::func: ABOUT TO USE KEY METHOD...\n";
$href->{KEY}->method();
print "EXT2::func: DONE!\n";
}
which resulted in:
EXT3: ABOUT TO GOTO EXT2::func - @_ IS (HASH(0x804d170) ARRAY(0x804d260) 3)
EXT2: ARRIVED AT EXT2::func - @_ IS ( )
EXT2::func: ABOUT TO USE KEY METHOD...
pid 37031 (perl), uid 303: exited on signal 11
> Signal numbers are system-dependent. Is that a SEGV?
This is on FreeBSD, so yeah a segfault.
>>Oddly enough, if I throw in the otherwise useless line:
>>
>> @_ = @_;
>>
>>just before the goto, suddenly it works again.
>>
>>So there is a workaround - either the odd '@_ = @_' thing which looks
>>too much like a smiley or instead of goto& just simply call the old
>>function as in $old->(@_), but I'm thinking the destruction of @_ and
>>the terminate on signal 11 thing may be a bug in perl itself.
>
> We (or anyone else concerned, like p5p) would have to see the effect.
> Your code doesn't show it.
I'm trying :) Its the useless-use-of-@_=@_ that makes me think it must
be something happening between chained goto's - somehow the link to @_
is being weakened to a point where the next goto ends up pointing to the
wrong peice of memory and segfaults. Since including the broken @_ in a
string still 'works' (ie doesn't cause a segfault) I'm guessing maybe a
screwed up internal perl structure that can't be dereferenced but can be
stringified? The 'bad' @_ stringifies as if it was an array filled with
empty strings.
I wasn't posting this with the intention of someone being able to fix it
on this information - obviously its not enough. I was hoping someone
with a bigger perl head than me could see the situation and maybe give
me some tips on how to try and replicate it for further debugging. The
main code has been running fine for some time - it was just a new
extension that must have gone just over the line that suddenly threw
everything out.
MB
------------------------------
Date: Mon, 07 Mar 2005 12:08:18 +1000
From: Matthew Braid <not@invalid.invalid>
Subject: Re: goto &Package::func destroying @_?!
Message-Id: <d0gd2i$2dev$1@bunyip2.cc.uq.edu.au>
Brian McCauley wrote:
> Matthew Braid wrote:
>
>> Unfortunately this is another one that I can't reproduce in a small
>> script, but maybe the description will trigger something from someone....
>
>
> It does.
>
> In the last few weeks I've seen a post that shows that there does appear
> to be a bug with the first element of @_ and goto.
>
> Unfortunately having searched comp.lang.perl.* and PerlMonks I can't
> locate it.
Damn, well I'll keep looking. In my case it's not just the first element
though - I'm expecting to get a hashref, and arrayref and a scalar, and
for all three I get something that stringifies as '' and segfaults on
dereference.
------------------------------
Date: Mon, 07 Mar 2005 10:33:50 +0800
From: GreenLeaf <newspost@kohombanDELETE.net>
Subject: Re: print isn't flashed using PERL by MSWin32 on Windows XP
Message-Id: <391sv8F5ug8i9U1@individual.net>
reyal wrote:
> Sorry to bother again, but it doesn't work.
Give examples (preferably the minimal code that reproduces the error) on
when or where it does not work. Your example from someone else's post is
a different matter that has nothing to do with flushing. Flushing issue
is not even applicable there because (among other things) the input line
you get from <STDIN> comes with a "\n", so a simple print would flush it
with or without autoflushing on.
Apparently the OP of the post you extracted was aware that the problem
was with the call to eof. Sinan and Anno clearly explained what happens
there. On your problem, the following code works for me as expected.
That is, if autoflush is set to 0, it waits 5 seconds to flush the
whole line.
Cheers :o),
sat
#! /usr/bin/perl
use strict;
use warnings;
print 'Enter autoflush value : ';
$_ = <>;
chomp;
$| = $_;
for (1..20) {
print time;
print "\n" unless ($_ % 5);
sleep(1);
}
__END__
------------------------------
Date: 07 Mar 2005 11:35:38 GMT
From: Villy Kruse <vek@station02.ohout.pharmapartners.nl>
Subject: Re: SOAP::Lite +wsdl
Message-Id: <slrnd2of49.t1.vek@station02.ohout.pharmapartners.nl>
On Sat, 05 Mar 2005 04:15:23 +0000,
Andrew Tkachenko <pobugfix@peterlink.ru> wrote:
>
> use SOAP::Lite;
> print SOAP::Lite
> -> service(?http://www.xmethods.net/sd/StockQuoteService.wsdl?)
> -> getQuote(?MSFT?);
>
> But how can I call getQuote as object method rather than class one ?
> Any help would be greatly appreciated.
>
This is basically the same as:
use SOAP::Lite;
my $obj = SOAP::Lite
-> service(?http://www.xmethods.net/sd/StockQuoteService.wsdl?);
print $obj -> getQuote(?MSFT?);
In the original example you have stacked object calls; the object returned
from the service method is used in a subsequent getQuote method call.
Most SOAP::Lite methods return the object itself so you can stack calls
in this way.
Villy
------------------------------
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 V10 Issue 7863
***************************************