[31642] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2905 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 8 06:09:23 2010

Date: Thu, 8 Apr 2010 03:09:06 -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           Thu, 8 Apr 2010     Volume: 11 Number: 2905

Today's topics:
        Correct way to save zip file after replacing member? <davidmichaelkarr@gmail.com>
    Re: Correct way to save zip file after replacing member <smallpond@juno.com>
        reading line from socket <ron.eggler@gmail.com>
    Re: reading line from socket <someone@example.com>
    Re: reading line from socket <willem@turtle.stack.nl>
    Re: reading line from socket <tadmc@seesig.invalid>
    Re: reading line from socket sln@netherlands.com
        SOAP::WSDL, wsdl2perl and soap 1.2 <franardone@googlemail.com>
    Re: SOAP::WSDL, wsdl2perl and soap 1.2 <RedGrittyBrick@spamweary.invalid>
    Re: software requirements again, take 483 <ben@morrow.me.uk>
    Re: STDIN number only <tzz@lifelogs.com>
    Re: STDIN number only sln@netherlands.com
    Re: STDIN number only <tzz@lifelogs.com>
    Re: VERSION in UNIVERSAL alternative? <ben@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 7 Apr 2010 09:31:19 -0700 (PDT)
From: "david.karr" <davidmichaelkarr@gmail.com>
Subject: Correct way to save zip file after replacing member?
Message-Id: <3855e952-c6d9-4754-b4d6-2604b2d62565@x3g2000yqd.googlegroups.com>

I've written a short utility script to replace a member in a zip file,
using the Archive::Zip module.  After calling "updateMember()", I'm
pretty sure I need to do something else to "finish" this, perhaps just
writing the file out.  Assuming my script has the original file name
and the "Zip" object, what are the steps I should follow to write out
this change to the original file name?  I'm testing this on Cygwin,
but it will need to work on Mac and Linux also (probably not an
issue).  I've read the Archive::Zip doc page, but I haven't seen
anything that clearly says what I need to do here.


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

Date: Wed, 07 Apr 2010 12:57:15 -0400
From: Steve C <smallpond@juno.com>
Subject: Re: Correct way to save zip file after replacing member?
Message-Id: <hpidhn$6mm$1@news.eternal-september.org>

david.karr wrote:
> I've written a short utility script to replace a member in a zip file,
> using the Archive::Zip module.  After calling "updateMember()", I'm
> pretty sure I need to do something else to "finish" this, perhaps just
> writing the file out.  Assuming my script has the original file name
> and the "Zip" object, what are the steps I should follow to write out
> this change to the original file name?  I'm testing this on Cygwin,
> but it will need to work on Mac and Linux also (probably not an
> issue).  I've read the Archive::Zip doc page, but I haven't seen
> anything that clearly says what I need to do here.

 From the doc, it looks like you want the overwrite method.


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

Date: Wed, 7 Apr 2010 11:31:22 -0700 (PDT)
From: cerr <ron.eggler@gmail.com>
Subject: reading line from socket
Message-Id: <a88580a1-d772-49a5-8662-6115a2c36011@x20g2000yqb.googlegroups.com>

Hi There,

I'm using something like:
  if (defined(<SOCKET>))
  {
    while (($line = <SOCKET>) && $count < $POSLIMIT){
 ...
 ...
and i'm getting following:
"Value of <HANDLE> construct can be "0"; test with defined() at ./
UpdateServer.pl line 831."
How can i get rid of this message? Thank you!
--
roN


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

Date: Wed, 07 Apr 2010 11:34:18 -0700
From: "John W. Krahn" <someone@example.com>
Subject: Re: reading line from socket
Message-Id: <Le4vn.7873$kj3.4552@newsfe08.iad>

cerr wrote:
> Hi There,
> 
> I'm using something like:
>   if (defined(<SOCKET>))
>   {
>     while (($line = <SOCKET>) && $count < $POSLIMIT){
> ...
> ...
> and i'm getting following:
> "Value of <HANDLE> construct can be "0"; test with defined() at ./
> UpdateServer.pl line 831."
> How can i get rid of this message? Thank you!

      while (defined($line = <SOCKET>) && $count < $POSLIMIT){




John
-- 
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity.               -- Damian Conway


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

Date: Wed, 7 Apr 2010 19:30:21 +0000 (UTC)
From: Willem <willem@turtle.stack.nl>
Subject: Re: reading line from socket
Message-Id: <slrnhrpnad.kjq.willem@turtle.stack.nl>

cerr wrote:
) Hi There,
)
) I'm using something like:
)   if (defined(<SOCKET>))

This reads a line from the socket and then throws it away.
Is this what you want ?

)   {
)     while (($line = <SOCKET>) && $count < $POSLIMIT){

If $count >= $POSLIMIT, then this reads a line from the socket
and then throws it away.  Is this what you want ?


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT


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

Date: Wed, 07 Apr 2010 16:31:00 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: reading line from socket
Message-Id: <slrnhrpu4q.ovq.tadmc@tadbox.sbcglobal.net>

Willem <willem@turtle.stack.nl> wrote:
> cerr wrote:
> ) Hi There,
> )
> ) I'm using something like:
> )   if (defined(<SOCKET>))
>
> This reads a line from the socket and then throws it away.


That's sure enough true.


> Is this what you want ?
>
> )   {
> )     while (($line = <SOCKET>) && $count < $POSLIMIT){
>
> If $count >= $POSLIMIT, then this reads a line from the socket
> and then throws it away.  Is this what you want ?


If $count >= $POSLIMIT, then this reads a line from the socket
and terminates the while loop.

The data is still safely tucked into $line.

Is that what the OP wants?


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

Date: Wed, 07 Apr 2010 14:41:51 -0700
From: sln@netherlands.com
Subject: Re: reading line from socket
Message-Id: <vsrpr5pp9v88o86m1aolvd8c2ncs5dj7il@4ax.com>

On Wed, 7 Apr 2010 11:31:22 -0700 (PDT), cerr <ron.eggler@gmail.com> wrote:

>Hi There,
>
>I'm using something like:
>  if (defined(<SOCKET>))
>  {
>    while (($line = <SOCKET>) && $count < $POSLIMIT){
>...
>...
>and i'm getting following:
>"Value of <HANDLE> construct can be "0"; test with defined() at ./
>UpdateServer.pl line 831."
>How can i get rid of this message? Thank you!

Krahn showed the fix for you.
This is a FAQ somewhere.

$line is evaluated as a conditional.
It is the result of the <HANDLE> read operation.
The read could return a '0' or 0, which equals false in a
conditional and breaks out of the loop.

In terms of defined(), all things are defined unless
its variable has the UNDEF flag set via some way,
$line = undef is one way.

The sucess of a call is usually returned via
undef. Since there is only 1 definition of undef,
most functions sneek it in on failure, otherwise the
test is on the data returned.

Adding a defined(($line = <SOCKET>)) around this really
checks if the read succeded or did not. At EOF, it will
return undef.

These are mostly the built-in functions that return undef
as a special meaning. Sometimes its a pain to have to use
the defined check all the time though. 

In general, asignments within conditionals can be tricky.
The trick is to know if undef as a return value is a factor
in the code flow.

Likewise, a test in any code flow:

$line = <HANDLE>;
if (defined( $line)) {
	# do other checks
	# do something with line, its valid data
}
else {
	# $line is undef, HANDLE is at eof
}

if (defined (0) and not 0)       # true
if (defined ("0") and not "0")   # true
if (defined ("") and not "")     # true


Read perlfunc on defined()
 
-sln


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

Date: Thu, 8 Apr 2010 00:15:42 -0700 (PDT)
From: Me <franardone@googlemail.com>
Subject: SOAP::WSDL, wsdl2perl and soap 1.2
Message-Id: <371d8a7f-a85f-4877-93a3-ebc54c48da7b@g11g2000yqe.googlegroups.com>

Hi all,
  I am trying to generate access classes for a webservice client using
wsdl2perl and I am encountering some problems:
1) The interface class is not created.
the wsdl I have uses soap1.2 namespace, if I change it to use plain
soap ("http://schemas.xmlsoap.org/wsdl/soap/") wsdl2perl manages to
create the interface class but then I get problem number 2

2) When I try to make a call using the autogenerated interface, the
remote server (over which I have no control) responds with:
"Cannot process the message because the content type 'text/xml;
charset=utf-8' was not the expected type 'application/soap+xml;
charset=utf-8'".

wsdl2perl also gives me the following warnings:
"XML Schema element <appinfo> is not implemented yet at /usr/share/
perl5/SOAP/WSDL/Expat/WSDLParser.pm line 254." (I get 4 of these).
and
"found unrecognised attribute {http://www.w3.org/2006/05/addressing/
wsdl}Action (ignored) at /usr/share/perl5/SOAP/WSDL/Base.pm line 130."
The latter comes from this element in the wsdl: '<wsdl:input
wsaw:Action="http://tempuri.org....'
Apparently it is not allowed to use namespaces for attribute names ?
(wsaw is "http://www.w3.org/2006/05/addressing/wsdl" in case that
matters).

I believe the server is a .NET thing.

I am quite unexperienced when it comes to XML and SOAP, any pointer
will be appreciated.

thanks


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

Date: Thu, 08 Apr 2010 10:50:09 +0100
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: SOAP::WSDL, wsdl2perl and soap 1.2
Message-Id: <4bbda6d3$0$2540$da0feed9@news.zen.co.uk>

On 08/04/2010 08:15, Me wrote:
> Hi all,
>    I am trying to generate access classes for a webservice client using
> wsdl2perl and I am encountering some problems:
> 1) The interface class is not created.
> the wsdl I have uses soap1.2 namespace, if I change it to use plain
> soap ("http://schemas.xmlsoap.org/wsdl/soap/") wsdl2perl manages to
> create the interface class but then I get problem number 2
>
> 2) When I try to make a call using the autogenerated interface, the
> remote server (over which I have no control) responds with:
> "Cannot process the message because the content type 'text/xml;
> charset=utf-8' was not the expected type 'application/soap+xml;
> charset=utf-8'".
>
> wsdl2perl also gives me the following warnings:
> "XML Schema element<appinfo>  is not implemented yet at /usr/share/
> perl5/SOAP/WSDL/Expat/WSDLParser.pm line 254." (I get 4 of these).
> and
> "found unrecognised attribute {http://www.w3.org/2006/05/addressing/
> wsdl}Action (ignored) at /usr/share/perl5/SOAP/WSDL/Base.pm line 130."
> The latter comes from this element in the wsdl: '<wsdl:input
> wsaw:Action="http://tempuri.org....'
> Apparently it is not allowed to use namespaces for attribute names ?
> (wsaw is "http://www.w3.org/2006/05/addressing/wsdl" in case that
> matters).
>
> I believe the server is a .NET thing.
>
> I am quite unexperienced when it comes to XML and SOAP, any pointer
> will be appreciated.


I've not tried wsdl2perl but I have generated Perl clients for non-Perl 
SOAP services and .Net clients for Perl SOAP services.

SOAP 1.2 tends to choke a few tools I've tried. I had to resort to trial 
and error on one occasion.

Perl modules such as SOAP::Lite are oriented to RPC/encoded style of 
SOAP calls whereas .Net is oriented towards Doc/Literal.

RPC/encoded example

   <soap:envelope>
     <soap:body>
       <ns:methodName>
         <param xsi:type="xsd:int">123</param>

DOC/Literal example

   <soap:envelope>
     <soap:body>
       <param>123</param>


Doc/Literal/Wrapped is a kind of combination of these two styles.

In past cases I've found the easiest approach is to use a sniffer 
(Wireshark is good) on a .Net client and tweak my Perl client until the 
on-the-wire packets match those of the .Net client. Obviously you can't 
do this if you don't have a sample .Net client (or can't generate one 
with .Net tools or mono etc).

There's also a difference in the way the HTTP SOAPAction header is 
constructed.

   $request->header(SOAPAction => qq("$uri#$method")); # perl service
   $request->header(SOAPAction => qq("$uri/$method")); # java service
   $request->header(SOAPAction => qq(""));             # java service

Some services don't care about the SOAPAction header, others do. Experiment.

The *Simple* Object Access Protocol *isn't* simple and real-life 
interoperability is disappointing.

-- 
RGB


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

Date: Wed, 7 Apr 2010 20:51:43 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: software requirements again, take 483
Message-Id: <fb4v87-qd1.ln1@osiris.mauzo.dyndns.org>


Quoth Charlton Wilbur <cwilbur@chromatico.net>:
> 
> If you want help, you've come to the right place.  If you want to vent
> about how miserable your life is and how nobody understands you,
> livejournal is that way.

+1

Ben



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

Date: Wed, 07 Apr 2010 09:05:05 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: STDIN number only
Message-Id: <87iq832wa6.fsf@lifelogs.com>

On Tue, 06 Apr 2010 14:09:07 -0700 sln@netherlands.com wrote: 

s> On Mon, 05 Apr 2010 20:44:59 -0700, sln@netherlands.com wrote:
>> On Mon, 05 Apr 2010 12:54:17 -0500, Don Pich <dpich@polartel.com> wrote:
>> 
>>> What I want to do is that if a user enters anything but a number from 0 
>>> to 254, they will get the print statement above.  If it is a number, then 
>>> flow it through.  I am having a very tough time trying to have this just 
>>> entered as a number.  I have tried various regex examples to fix this.  
>>> But none will kick out an error if I enter a string of text.
>>> 
>>> different regex strings I've tried:
>>> 
>>> $OCT1 =~ s/.*?(\d+).*/$1/;
>>> m/^-?\d+$/
>>> m/^-?\d+[\/|\.]\d+$/
>>> 
>> 
>> You could always do it all at once instead of single quad parts.
>> 
s> This version is a little more forgiving when enterring the ip.
s> It mainly gets the dotted quad part, and optional bits in
s> CIDR notation.
s> I was going to do this anyway, if you need it take it.
s> The network stuff at the bottom was gleaned from Wikipedia:
s>   http://en.wikipedia.org/wiki/Subnetwork
s> I'm not a network expert, so its roll your own or whatever.

s> Without the CIDR notation, it just spits out the input IP.

I don't think the OP asked for IP matching, but if he did I would have
pointed him to Regexp::Common::net.

Ted


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

Date: Wed, 07 Apr 2010 07:56:56 -0700
From: sln@netherlands.com
Subject: Re: STDIN number only
Message-Id: <fh5pr5dq1it4a9uk9clkks4u0jgmt93g11@4ax.com>

On Wed, 07 Apr 2010 09:05:05 -0500, Ted Zlatanov <tzz@lifelogs.com> wrote:

>On Tue, 06 Apr 2010 14:09:07 -0700 sln@netherlands.com wrote: 
>
>s> On Mon, 05 Apr 2010 20:44:59 -0700, sln@netherlands.com wrote:
>>> On Mon, 05 Apr 2010 12:54:17 -0500, Don Pich <dpich@polartel.com> wrote:
>>> 
>>>> What I want to do is that if a user enters anything but a number from 0 
>>>> to 254, they will get the print statement above.  If it is a number, then 
>>>> flow it through.  I am having a very tough time trying to have this just 
>>>> entered as a number.  I have tried various regex examples to fix this.  
>>>> But none will kick out an error if I enter a string of text.
>>>> 
>>>> different regex strings I've tried:
>>>> 
>>>> $OCT1 =~ s/.*?(\d+).*/$1/;
>>>> m/^-?\d+$/
>>>> m/^-?\d+[\/|\.]\d+$/
>>>> 
>>> 
>>> You could always do it all at once instead of single quad parts.
>>> 
>s> This version is a little more forgiving when enterring the ip.
>s> It mainly gets the dotted quad part, and optional bits in
>s> CIDR notation.
>s> I was going to do this anyway, if you need it take it.
>s> The network stuff at the bottom was gleaned from Wikipedia:
>s>   http://en.wikipedia.org/wiki/Subnetwork
>s> I'm not a network expert, so its roll your own or whatever.
>
>s> Without the CIDR notation, it just spits out the input IP.
>
>I don't think the OP asked for IP matching, but if he did I would have
>pointed him to Regexp::Common::net.
>
>Ted

Well, no harm no foul then. What do you think the OP is asking for?
I never heard of IP matching or looked at net modules.
To me, it looks like he sits in a loop, getting and validating
ip quad parts and cidr notation.

I'm glad I didn't write him a Net module, thanks for stopping
me!

-sln

===============================================================

From: sln@netherlands.com
Newsgroups: comp.lang.perl.misc
Subject: Re: Simple regex question

On Tue, 09 Mar 2010 08:31:48 -0600, Don Pich <dpich@polartel.com> wrote:

>I was wondering if there is a way to have perl check for a whole number?
>
>In an equation, if I have 16/4, it will come up with 4 and will set the 
>"check" to true.  If I have 16/5, it will come up with 3.2 and set the 
>condition false.
>
>Is there a method to get this into an if/else condition?

print "whole 16/4\n" if !(16 % 4);
print "fraction 11/5\n" if 16 % 5;

Whats regex have to do with it?

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

From: Don Pich <dpich@polartel.com>
Subject: Re: Simple regex question

Probably nothing.  But not being 100% efficient with Perl, I wasn't sure.

So let's add another twist to this.  The reason I asked this question is 
that I have a script that is prompting a user for an IP address.  I have 
them entering it one octet at a time.  The first three octets should be 
fine with whatever is place in stin.  But the forth octet will need to 
follow the subnet rules (i.e., the network address of a /30 would have 
the fourth octet as 0, 4, 8, 12, 16 etc.  The network address of a /29 
would have the fourth octet as 0, 8, 16, 24, 32).

How would I apply the following code so that it will follow subnet rules?

Here is the piece of the code that picks out the octets:

_____CODE______


# Find out the IP address
while ($OCT1_COUNT == 1)
{
  print "\nWhat is the First octet?  ";
  $OCT1 = <STDIN> ;
    if (($OCT1 < 0) || ($OCT1 > 255))
      {
	print "That number is not between 1 and 254.\n";
      }
    else
      {
	chomp ($OCT1);
	$OCT1_COUNT++;
      }
}
while ($OCT2_COUNT == 1)
{
  print "\nWhat is the Second octet?  ";
  $OCT2 = <STDIN> ;
    if (($OCT1 < 0) || ($OCT1 > 255))
      {
	print "That number is not between 1 and 254.\n";
      }
    else
      {
	chomp ($OCT2);
	$OCT2_COUNT++;
      }
}
while ($OCT3_COUNT == 1)
{
  print "\nWhat is the Third octet?  ";
  $OCT3 = <STDIN> ;
    if (($OCT1 < 0) || ($OCT1 > 255))
      {
	print "That number is not between 1 and 254.\n";
      }
    else
      {
	chomp ($OCT3);
	$OCT3_COUNT++;
      }
}
while ($OCT4_COUNT == 1)
{
  print "\nWhat is the Fourth octet?  ";
  $OCT4 = <STDIN> ;
    if (($OCT1 < 0) || ($OCT1 > 255))
      {
	print "That number is not between 1 and 254.\n";
      }
    else
      {
	chomp ($OCT4);
	$OCT4_COUNT++;
      }
}



_____/CODE_____


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

Date: Wed, 07 Apr 2010 12:02:11 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: STDIN number only
Message-Id: <876343fb70.fsf@lifelogs.com>

On Wed, 07 Apr 2010 07:56:56 -0700 sln@netherlands.com wrote: 

s> On Wed, 07 Apr 2010 09:05:05 -0500, Ted Zlatanov <tzz@lifelogs.com> wrote:
>> I don't think the OP asked for IP matching, but if he did I would have
>> pointed him to Regexp::Common::net.

s> Well, no harm no foul then. What do you think the OP is asking for?
s> I never heard of IP matching or looked at net modules.
s> To me, it looks like he sits in a loop, getting and validating
s> ip quad parts and cidr notation.

s> I'm glad I didn't write him a Net module, thanks for stopping
s> me!

I (or the NNTP server) missed the part where he explained in more
detail, and which you quoted.  Sorry about that.  I left most of the
explanation below for clarity.

I would use Net::Netmask to check that the provided IP fits within the
required netmask.  It supports almost any operation you may need in that
direction.  Together with Regexp::Common::net for input validation it
should be pretty easy.

It may actually be fun to use Term::Readline completion for this.  It's
pretty easy, you just give it 0-255 as the options for each of the first
three octets and then you calculate the completions for the last one
based on the text you have so far.

Ted

s> ------------------------------------------

s> From: Don Pich <dpich@polartel.com>
s> Subject: Re: Simple regex question

s> Probably nothing.  But not being 100% efficient with Perl, I wasn't sure.

s> So let's add another twist to this.  The reason I asked this question is 
s> that I have a script that is prompting a user for an IP address.  I have 
s> them entering it one octet at a time.  The first three octets should be 
s> fine with whatever is place in stin.  But the forth octet will need to 
s> follow the subnet rules (i.e., the network address of a /30 would have 
s> the fourth octet as 0, 4, 8, 12, 16 etc.  The network address of a /29 
s> would have the fourth octet as 0, 8, 16, 24, 32).


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

Date: Wed, 7 Apr 2010 09:36:43 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: VERSION in UNIVERSAL alternative?
Message-Id: <rpst87-emb.ln1@osiris.mauzo.dyndns.org>


Quoth John Bokma <john@castleamber.com>:
> Hi,
> 
> I currently use an eval to obtain VERSION of the parent class [1]. I noted
> that UNIVERSAL has VERSION, however,

UNIVERSAL has a version *method*. It's a bad idea to call any of
UNIVERSAL's methods as *functions*, since that prevents classes from
overriding them.

> http://perldoc.perl.org/UNIVERSAL.html
> 
> states that " import ... and VERSION ), however it is usually harmful to
> do so. Please don't do this in new code.
> 
> So, what's the alternative / better solution (and why isn't this in the
> documentation ;-) ).
> 
> [1] my $package = ref $self;
>     my $version = eval "\$${package}::VERSION";

    my $version = eval { $package->VERSION };

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


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