[31583] in Perl-Users-Digest
Perl-Users Digest, Issue: 2842 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 1 18:09:22 2010
Date: Mon, 1 Mar 2010 15:09:06 -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, 1 Mar 2010 Volume: 11 Number: 2842
Today's topics:
Re: eval exit/exec (was: macros: return or exit) <marc.girod@gmail.com>
Re: eval exit/exec (was: macros: return or exit) <ben@morrow.me.uk>
extract number from binary string <no.mail@spam.no>
Re: extract number from binary string <uri@StemSystems.com>
Re: extract number from binary string <someone@example.com>
Re: extract number from binary string <o.almer@sms.ed.ac.uk>
Re: extract number from binary string <uri@StemSystems.com>
Re: extract number from binary string <o.almer@sms.ed.ac.uk>
Re: extract number from binary string sln@netherlands.com
Generate a wsdl file from a cgi script <nabil.baklouti@gmail.com>
Re: Generate a wsdl file from a cgi script <glex_no-spam@qwest-spam-no.invalid>
GraphicsMagick for WinPerl 5.10.x ? <dam-kat-jensen@gmail-kat-.com>
Re: GraphicsMagick for WinPerl 5.10.x ? <ben@morrow.me.uk>
Re: Parsing HTML with HTML::Tree <nickli2000@gmail.com>
Re: Recursion without lists <rvtol+usenet@xs4all.nl>
Re: Recursion without lists <rvtol+usenet@xs4all.nl>
Re: Recursion without lists (Jens Thoms Toerring)
Re: unicode characters with PerlMagick <dam-kat-jensen@gmail-kat-.com>
Re: unicode characters with PerlMagick <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 1 Mar 2010 11:14:20 -0800 (PST)
From: Marc Girod <marc.girod@gmail.com>
Subject: Re: eval exit/exec (was: macros: return or exit)
Message-Id: <887985c5-c38f-4839-90a1-e4d1a868440c@15g2000yqa.googlegroups.com>
On Feb 28, 10:34=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> > I.e. I do not override the builtin at all, but
> > only the method, right?
> > I just don't care anymore for the builtin...
>
> Yes, that's right.
Fortunately, in that case, I have an other
solution.
I can redefine:
sub exec {
my $self =3D shift;
die $self->system(@_);
}
Nobody else uses the naked 'exec' in that scope.
I.e. I am afraid that the current situation:
die system(@_)
even if it does pass the object reference as first
parameter, ends up calling the builtin?
Marc
------------------------------
Date: Mon, 1 Mar 2010 19:27:32 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: eval exit/exec (was: macros: return or exit)
Message-Id: <42ht57-aaj2.ln1@osiris.mauzo.dyndns.org>
Quoth Marc Girod <marc.girod@gmail.com>:
> On Feb 28, 10:34 pm, Ben Morrow <b...@morrow.me.uk> wrote:
>
> > > I.e. I do not override the builtin at all, but
> > > only the method, right?
> > > I just don't care anymore for the builtin...
> >
> > Yes, that's right.
>
> Fortunately, in that case, I have an other
> solution.
> I can redefine:
>
> sub exec {
> my $self = shift;
> die $self->system(@_);
> }
>
> Nobody else uses the naked 'exec' in that scope.
>
> I.e. I am afraid that the current situation:
>
> die system(@_)
>
> even if it does pass the object reference as first
> parameter, ends up calling the builtin?
*Yes*. A function call that just happens to pass a reference is quite
different from a method call.
Ben
------------------------------
Date: Mon, 01 Mar 2010 19:17:54 +0100
From: Looden <no.mail@spam.no>
Subject: extract number from binary string
Message-Id: <4b8c04d2$0$2883$ba620e4c@news.skynet.be>
Hi
I'm parsing a binary string, which encodes a number.
I don't know the length of the string in advance: 1, 2, 3 or 4 bytes.
The bytes of the string are in network order.
How can I retrieve the number?
I've written this sub, there must be a better way:
sub parse_number {
my $arg = shift;
my $size = length($arg);
my $value = 0;
my $buf;
for (my $i=($size-1);$i>=0;$i--){
$buf = unpack "C", (substr $arg, $i, 1);
$value += $buf * (256**($size-$i-1));
}
return $value;
}
Note: If the length of the string was always 2 bytes, I could just do:
sub parse_n { return unpack "n", shift; }
Thanks in advance.
------------------------------
Date: Mon, 01 Mar 2010 13:28:25 -0500
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: extract number from binary string
Message-Id: <87ocj76gmu.fsf@quad.sysarch.com>
>>>>> "L" == Looden <no.mail@spam.no> writes:
L> I'm parsing a binary string, which encodes a number. I don't know
L> the length of the string in advance: 1, 2, 3 or 4 bytes. The bytes
L> of the string are in network order. How can I retrieve the number?
L> sub parse_number {
L> my $arg = shift;
pick a better name for that. $arg is generic.
L> my $size = length($arg);
L> my $value = 0;
L> my $buf;
L> for (my $i=($size-1);$i>=0;$i--){
L> $buf = unpack "C", (substr $arg, $i, 1);
L> $value += $buf * (256**($size-$i-1));
L> }
L> return $value;
L> }
much simpler would be to unpack the bytes to an array and then do the
multiply/add stuff in a loop. untested and unfinished:
my @bytes = unpack 'C*, $byte_string ;
my $value ;
for my $byte ( @bytes ) {
multiply/add code
}
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Mon, 01 Mar 2010 10:29:38 -0800
From: "John W. Krahn" <someone@example.com>
Subject: Re: extract number from binary string
Message-Id: <mITin.38824$K81.16855@newsfe18.iad>
Looden wrote:
> Hi
> I'm parsing a binary string, which encodes a number.
> I don't know the length of the string in advance: 1, 2, 3 or 4 bytes.
> The bytes of the string are in network order.
> How can I retrieve the number?
>
> I've written this sub, there must be a better way:
>
> sub parse_number {
> my $arg = shift;
> my $size = length($arg);
> my $value = 0;
> my $buf;
> for (my $i=($size-1);$i>=0;$i--){
> $buf = unpack "C", (substr $arg, $i, 1);
> $value += $buf * (256**($size-$i-1));
> }
> return $value;
> }
>
> Note: If the length of the string was always 2 bytes, I could just do:
> sub parse_n { return unpack "n", shift; }
$ perl -le'
my @strings = ( "\xa", "\xb\x1", "\xc\x2\x3", "\xd\x4\x5\x6" );
for my $string ( @strings ) {
my $number = substr "\0\0\0" . $string, -4;
print unpack "N", $number;
}
'
10
2817
786947
218367238
John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity. -- Damian Conway
------------------------------
Date: Mon, 1 Mar 2010 18:43:23 +0000
From: Oscar Almer <o.almer@sms.ed.ac.uk>
Subject: Re: extract number from binary string
Message-Id: <20100301184323.4d6e33b5@sms.ed.ac.uk>
On Mon, 01 Mar 2010 19:17:54 +0100
Looden <no.mail@spam.no> wrote:
> Hi
> I'm parsing a binary string, which encodes a number.
> I don't know the length of the string in advance: 1, 2, 3 or 4 bytes.
> The bytes of the string are in network order.
> How can I retrieve the number?
>
> I've written this sub, there must be a better way:
>
> sub parse_number {
> my $arg = shift;
> my $size = length($arg);
> my $value = 0;
> my $buf;
> for (my $i=($size-1);$i>=0;$i--){
> $buf = unpack "C", (substr $arg, $i, 1);
> $value += $buf * (256**($size-$i-1));
> }
> return $value;
> }
>
> Note: If the length of the string was always 2 bytes, I could just
> do: sub parse_n { return unpack "n", shift; }
>
> Thanks in advance.
>
I seem to recall (I wrote some code that parses binary strings recently)
that oct() does that, if you prefix it with "0b" to indicate
binaryness. Some application of reverse / substr might be useful to
handle byte ordering.
I could be wrong.
//Oscar
------------------------------
Date: Mon, 01 Mar 2010 13:47:35 -0500
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: extract number from binary string
Message-Id: <87fx4j6fqw.fsf@quad.sysarch.com>
>>>>> "OA" == Oscar Almer <o.almer@sms.ed.ac.uk> writes:
OA> I seem to recall (I wrote some code that parses binary strings
OA> recently) that oct() does that, if you prefix it with "0b" to
OA> indicate binaryness. Some application of reverse / substr might be
OA> useful to handle byte ordering.
OA> I could be wrong.
you are wrong. :)
she has real binary bytes. 0b deals with bits in ascii form.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Mon, 1 Mar 2010 18:53:10 +0000
From: Oscar Almer <o.almer@sms.ed.ac.uk>
Subject: Re: extract number from binary string
Message-Id: <20100301185310.72baf172@sms.ed.ac.uk>
On Mon, 01 Mar 2010 13:47:35 -0500
"Uri Guttman" <uri@StemSystems.com> wrote:
> OA> I could be wrong.
>
> you are wrong. :)
>
> she has real binary bytes. 0b deals with bits in ascii form.
>
> uri
>
Ah, My bad.
I apologize and retract the previous.
//Oscar
------------------------------
Date: Mon, 01 Mar 2010 12:51:27 -0800
From: sln@netherlands.com
Subject: Re: extract number from binary string
Message-Id: <fu9oo597e6bsf5rme0uhbkl424k3vnh8oh@4ax.com>
On Mon, 01 Mar 2010 19:17:54 +0100, Looden <no.mail@spam.no> wrote:
>Hi
>I'm parsing a binary string, which encodes a number.
>I don't know the length of the string in advance: 1, 2, 3 or 4 bytes.
>The bytes of the string are in network order.
>How can I retrieve the number?
>
>I've written this sub, there must be a better way:
>
>sub parse_number {
> my $arg = shift;
> my $size = length($arg);
> my $value = 0;
> my $buf;
> for (my $i=($size-1);$i>=0;$i--){
> $buf = unpack "C", (substr $arg, $i, 1);
> $value += $buf * (256**($size-$i-1));
> }
> return $value;
> }
>
>Note: If the length of the string was always 2 bytes, I could just do:
>sub parse_n { return unpack "n", shift; }
>
>Thanks in advance.
I guess you could also do:
sub parse_number {
my $arg = shift;
vec("\0"x(4-length $arg).$arg, 0, 32);
}
-sln
------------------------------
Date: Mon, 1 Mar 2010 06:10:16 -0800 (PST)
From: "NABIL.B" <nabil.baklouti@gmail.com>
Subject: Generate a wsdl file from a cgi script
Message-Id: <512accfc-e823-4203-a6fc-1a0b34dc29f6@q23g2000yqd.googlegroups.com>
Hi,
I am very new in web service with the perl language so, i writed a cgi
script (as server) and a pl script (as client).
Now, i want to generate a wsdl file to make a web service composition.
Please, tell me how can i make this task?
I spent a lot of time without result.
Best regards
Nabil
------------------------------
Date: Mon, 01 Mar 2010 14:09:25 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Generate a wsdl file from a cgi script
Message-Id: <4b8c1ef5$0$48214$815e3792@news.qwest.net>
NABIL.B wrote:
> Hi,
> I am very new in web service with the perl language so, i writed a cgi
> script (as server) and a pl script (as client).
> Now, i want to generate a wsdl file to make a web service composition.
> Please, tell me how can i make this task?
> I spent a lot of time without result.
I've used WSDL::Generator before, and it looks like there might
be a few other solutions:
http://search.cpan.org/search?query=wsdl&mode=all
I always, always, always run into problems with clients written
in Java or .Net when they try to consume a generated WSDL, for
a Web Service written in perl ( e.g. SOAP::Lite), or trying
to write one manually, unless the service is very simple. For
such a simple standard, I've found it's nearly impossible to
create one manually that works for all clients.
If you're using perl on the client side too, it's much more
forgiving and generating the WSDL works very nicely. YMMV.
------------------------------
Date: 01 Mar 2010 18:38:17 GMT
From: Torben <dam-kat-jensen@gmail-kat-.com>
Subject: GraphicsMagick for WinPerl 5.10.x ?
Message-Id: <Xns9D2EC7C47FD01myicqgmxnet@130.225.254.104>
I am doing a project where I need to create graphics from Perl.
Spent around two entire days being frustrated about the combinations of
ImageMagick / GraphicsMagick and Perl.
Situation:
* ImageMagick seems to install for Perl 5.10.x, but is incredibly slow when
doing 1-bit BMP images on Win32.
* GraphicsMagick is much faster, but even the latest version 1.3.11 from
Feb 2010 simply refuses to install on Perl 5.10. It will only install on
Perl 5.8.x. The ppm install file "Graphics-Magick.ppd" mentions only 5.8
(<ARCHITECTURE NAME="MSWin32-x86-multi-thread-5.8" />)
So my question is: with Perl being at 5.10 officially, why is
GraphicsMagick still only supporting 5.8.x ?
Is there a way to trick GraphicsMagick to use perl 5.10.x ? Simply
replacing/renaming perlxxx.dll won't work.
Oh, and btw: Perl here means ActiveState Perl for Win32. Did not find a way
to install GraphicsMagick for Strawberry Perl.
Thanks for any input.
------------------------------
Date: Mon, 1 Mar 2010 19:22:51 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: GraphicsMagick for WinPerl 5.10.x ?
Message-Id: <bpgt57-aaj2.ln1@osiris.mauzo.dyndns.org>
Quoth Torben <dam-kat-jensen@gmail-kat-.com>:
> I am doing a project where I need to create graphics from Perl.
>
> Spent around two entire days being frustrated about the combinations of
> ImageMagick / GraphicsMagick and Perl.
>
> Situation:
>
> * ImageMagick seems to install for Perl 5.10.x, but is incredibly slow when
> doing 1-bit BMP images on Win32.
>
> * GraphicsMagick is much faster, but even the latest version 1.3.11 from
> Feb 2010 simply refuses to install on Perl 5.10. It will only install on
> Perl 5.8.x. The ppm install file "Graphics-Magick.ppd" mentions only 5.8
> (<ARCHITECTURE NAME="MSWin32-x86-multi-thread-5.8" />)
>
>
> So my question is: with Perl being at 5.10 officially, why is
> GraphicsMagick still only supporting 5.8.x ?
Since it isn't on CPAN, you'll have to ask the GM authors about that.
> Is there a way to trick GraphicsMagick to use perl 5.10.x ? Simply
> replacing/renaming perlxxx.dll won't work.
No. You need to rebuild the module against 5.10. If you can, it looks
like rebuilding GM from source would be the easiest way. If you are
using AS Perl you will need a copy of MSVC 6 for this, since I suspect
the AS/gcc emulation stuff won't work right.
> Oh, and btw: Perl here means ActiveState Perl for Win32. Did not find a way
> to install GraphicsMagick for Strawberry Perl.
According to INSTALL-unix.txt in the source distro, you should be able
to build GM with Strawberry's bundled compiler, and then build and
install the perl bindings the same way. Alternatively you could try
hacking the build process to just build the perl bindings against an
installed GM. I would start with PerlMagick\Makefile.nt, since it has
less hard-coded rubbish than the Makefile.PL, and try removing the DEFINE
line and editing the LIBS line to point to the right place.
Ben
------------------------------
Date: Mon, 1 Mar 2010 07:37:42 -0800 (PST)
From: Ninja Li <nickli2000@gmail.com>
Subject: Re: Parsing HTML with HTML::Tree
Message-Id: <346da9b8-44c5-4776-8c35-d61b67180d3d@f35g2000yqd.googlegroups.com>
Tad,
Thanks for your advice. You hit the nail on the head and it works
well now.
Nick
------------------------------
Date: Mon, 01 Mar 2010 19:49:49 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: Recursion without lists
Message-Id: <4b8c0c4d$0$22913$e4fe514c@news.xs4all.nl>
Simon Andrews wrote:
> "Take the numbers 123456789. Insert between each number either a + * or
> nothing and find the two equations whose answer is 2002"
eval==2002 and print "$_ = 2002" while glob(join "{+,\\*,}", 1..9);
--
Ruud
------------------------------
Date: Mon, 01 Mar 2010 20:13:23 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: Recursion without lists
Message-Id: <4b8c11d3$0$22945$e4fe514c@news.xs4all.nl>
Dr.Ruud wrote:
> Simon Andrews wrote:
>> "Take the numbers 123456789. Insert between each number either a + *
>> or nothing and find the two equations whose answer is 2002"
>
> eval==2002 and print "$_ = 2002" while glob(join "{+,\\*,}", 1..9);
perl -wle '
eval==$ARGV[0] and print "$_ = $ARGV[0]"
while glob(join "{+,-,\\*,/,}", 1..9);
' 1962
1+2-3+45*6*7+8*9 = 1962
1+2*34*5*6-7-8*9 = 1962
1+234*56/7+89 = 1962
12*3*45/6*7+8*9 = 1962
12*3/4*5*6*7+8*9 = 1962
123*4*5+6-7*8*9 = 1962
--
Ruud
------------------------------
Date: 1 Mar 2010 21:57:02 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: Recursion without lists
Message-Id: <7v2rheFgdmU2@mid.uni-berlin.de>
Dr.Ruud <rvtol+usenet@xs4all.nl> wrote:
> Simon Andrews wrote:
> > "Take the numbers 123456789. Insert between each number either a + * or
> > nothing and find the two equations whose answer is 2002"
> eval==2002 and print "$_ = 2002" while glob(join "{+,\\*,}", 1..9);
Nice! I never did imagine that you can use 'glob' like this. Things
like that are the one of the reason why reading clpm is so useful;-)
Best regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
------------------------------
Date: 01 Mar 2010 18:47:05 GMT
From: Torben <dam-kat-jensen@gmail-kat-.com>
Subject: Re: unicode characters with PerlMagick
Message-Id: <Xns9D2EC941EAD32myicqgmxnet@130.225.254.104>
"guba@vi-anec.de" <guba@vi-anec.de> wrote in news:f1134f0d-726b-4c33-9900-
814896dca926@g31g2000yqc.googlegroups.com:
> How can I put a character code like U+0E84 in the variable $text
> so that it is recognized and what font should I install/specify?
> Thank you very much!!
As someone else pointed out, it just plain works.. :)
Either use
$t = "\x{0E84}";
or just put the text directly in the quote, if your file is stored in UTF-8
format.
I have just completed a project where I did BMPs with hindi text.
This is what I had to do:
* use utf-8 in Perl
* store the perl source file as UTF-8
* I took the strings to annotate from a different file. This file was also
stored as UTF-8
It was not necessary to specify encode=>'UTF-8' in $image->Annotate
The nice thing about Perl is that UniCode and utf8 just works.
------------------------------
Date: Mon, 1 Mar 2010 19:25:17 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: unicode characters with PerlMagick
Message-Id: <ttgt57-aaj2.ln1@osiris.mauzo.dyndns.org>
Quoth Torben <dam-kat-jensen@gmail-kat-.com>:
>
> The nice thing about Perl is that UniCode and utf8 just works.
Hmmmmmm. You clearly haven't been following the interminable 'Unicode is
irrepairably broken, whatever are we to do??' threads on p5p... :)
Ben
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 2842
***************************************