[28229] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9593 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 11 18:05:41 2006

Date: Fri, 11 Aug 2006 15:05: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           Fri, 11 Aug 2006     Volume: 10 Number: 9593

Today's topics:
        autosave everytime loops runs <Shani718@gmail.com>
    Re: autosave everytime loops runs <jgibson@mail.arc.nasa.gov>
    Re: autosave everytime loops runs <bik.mido@tiscalinet.it>
    Re: How to send command line options into test scripts? <mumia.w.18.spam+nospam.usenet@earthlink.net>
        Implicit iterator variable $_ changing to ### upon vari <dbasch@yahoo.com>
    Re: Implicit iterator variable $_ changing to ### upon  <dbasch@yahoo.com>
    Re: Implicit iterator variable $_ changing to ### upon  <bik.mido@tiscalinet.it>
    Re: Implicit iterator variable $_ changing to ### upon  <dbasch@yahoo.com>
    Re: The assignment of command output to an array hangs. <mritty@gmail.com>
    Re: The assignment of command output to an array hangs. <kaleem177@gmail.com>
    Re: The assignment of command output to an array hangs. <mritty@gmail.com>
    Re: The assignment of command output to an array hangs. <kaleem177@gmail.com>
    Re: The assignment of command output to an array hangs. <mritty@gmail.com>
    Re: The assignment of command output to an array hangs. <mumia.w.18.spam+nospam.usenet@earthlink.net>
    Re: The assignment of command output to an array hangs. <bik.mido@tiscalinet.it>
        win32 sysread on socket hangs when requested == receive <none@not.no>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 11 Aug 2006 11:45:38 -0700
From: "Shan" <Shani718@gmail.com>
Subject: autosave everytime loops runs
Message-Id: <1155321938.120111.274250@75g2000cwc.googlegroups.com>

ok so I have the following:

open my $OUT, '>', 'write.tsv' or die "Error: $!";

write.tsv is the file I want my results printed to.

I want the file to be saved everytime a loop runs so that if the
program crashes I still have the information that was processed.

So i guess I need a save statement inside the loop but i Dont know of
any statements, do yoo?

Thanks in advance



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

Date: Fri, 11 Aug 2006 12:18:06 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: autosave everytime loops runs
Message-Id: <110820061218065280%jgibson@mail.arc.nasa.gov>

In article <1155321938.120111.274250@75g2000cwc.googlegroups.com>, Shan
<Shani718@gmail.com> wrote:

> ok so I have the following:
> 
> open my $OUT, '>', 'write.tsv' or die "Error: $!";
> 
> write.tsv is the file I want my results printed to.
> 
> I want the file to be saved everytime a loop runs so that if the
> program crashes I still have the information that was processed.

Perl doesn't have a "save" statement. I believe what you are saying is
that you want to write your data out to the file every time the loop
runs. So do so.

> 
> So i guess I need a save statement inside the loop but i Dont know of
> any statements, do yoo?

The Perl statements to write to a file are print and printf (and in
more complex or binary applications, write and syswrite.

perldoc -f print
perldoc -f printf

If you want to overwrite the previous contents of the file, thereby
updating the file for each iteration of the loop, you can close and
re-open the file, or use the seek function to write at the beginning of
the file.

perldoc -f seek

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


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

Date: 11 Aug 2006 22:32:51 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: autosave everytime loops runs
Message-Id: <8aqpd29m8hcrleefagjfo6esq6lqmlj8a7@4ax.com>

On 11 Aug 2006 11:45:38 -0700, "Shan" <Shani718@gmail.com> wrote:

>So i guess I need a save statement inside the loop but i Dont know of
                     ^^^^
                     ^^^^

print()?


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Fri, 11 Aug 2006 18:57:25 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: How to send command line options into test scripts?
Message-Id: <pq4Dg.7489$0e5.3373@newsread4.news.pas.earthlink.net>

On 08/11/2006 11:03 AM, yusuf wrote:
>> go to CPAN. search for GetOpt::Long:
>> http://search.cpan.org/~jv/Getopt-Long-2.35/lib/Getopt/Long.pm
>>
>> This should help you do what you require.
> 
> This does not work with Test::Harness. It considers the options that 
> you pass into the test file as invalid. See my previous posting with 
> the code.
> 

Use stub scripts to adapt Test::Harness to your executables. 
You would use Test::Harness to invoke the stub scripts, and 
the stub scripts would invoke the executables with parameters.

You should have been able to figure this out yesterday.


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

Date: 11 Aug 2006 13:34:56 -0700
From: "Derek Basch" <dbasch@yahoo.com>
Subject: Implicit iterator variable $_ changing to ### upon variable assignment?
Message-Id: <1155328496.639567.185110@b28g2000cwb.googlegroups.com>

Hello all,

I have ran into a very confusing problem and I hoped someone could help
me. This function is supposed to return a hash of the accessors and
their associated values for a given class.


------------------------------------------
package Test;

sub accessors_values {
  my $self = shift;
  my %accessors_values;

  foreach $_ ($self->accessors()) {
    print "$_\n";
    my $value = $self->_accessor_class($_)->get($_);
    print "$_ : $value\n";
  }
  return %accessors_values;
}

 ........

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

Gives this output:
------------------------------------------
password
### : carefree
user_id
### : 323227
first_login
### : 2006.08.08.12.47.13
last_login
### : 2006.08.08.12.47.13
------------------------------------------

Where the heck is the '###' coming from? How is assigning a value to
the $value variable causing the implicit iterator variable $_ to become
'###' ?

The functions that the code calls are large so I will give a synopsis
of what they return:

$self->accessors returns an array of accessor names
$self->_accessor_class returns a hash ref to a class
$self->get returns a scalar value

Any help is greatly appreciated.

Thanks,
Derek Basch



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

Date: 11 Aug 2006 13:55:03 -0700
From: "Derek Basch" <dbasch@yahoo.com>
Subject: Re: Implicit iterator variable $_ changing to ### upon variable assignment?
Message-Id: <1155329703.456244.239080@h48g2000cwc.googlegroups.com>


Derek Basch wrote:
> Hello all,
>
> I have ran into a very confusing problem and I hoped someone could help
> me. This function is supposed to return a hash of the accessors and
> their associated values for a given class.
>
>
> ------------------------------------------
> package Test;
>
> sub accessors_values {
>   my $self = shift;
>   my %accessors_values;
>
>   foreach $_ ($self->accessors()) {
>     print "$_\n";
>     my $value = $self->_accessor_class($_)->get($_);
>     print "$_ : $value\n";
>   }
>   return %accessors_values;
> }
>
> ........
>
> ------------------------------------------
>
> Gives this output:
> ------------------------------------------
> password
> ### : carefree
> user_id
> ### : 323227
> first_login
> ### : 2006.08.08.12.47.13
> last_login
> ### : 2006.08.08.12.47.13
> ------------------------------------------
>
> Where the heck is the '###' coming from? How is assigning a value to
> the $value variable causing the implicit iterator variable $_ to become
> '###' ?
>
> The functions that the code calls are large so I will give a synopsis
> of what they return:
>
> $self->accessors returns an array of accessor names
> $self->_accessor_class returns a hash ref to a class
> $self->get returns a scalar value
>
> Any help is greatly appreciated.
>
> Thanks,
> Derek Basch

I answered my own question. The implicit iterator was apparently being
set to "##" by one of the functions that I called from within the sub.
I didn't realize that it could be affected in such a way. Live and
learn I guess.

Thanks Anyways,
Derek Basch



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

Date: 11 Aug 2006 23:20:17 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Implicit iterator variable $_ changing to ### upon variable assignment?
Message-Id: <4hspd2d4bmob6felge4die3r4osj95bjjs@4ax.com>

On 11 Aug 2006 13:34:56 -0700, "Derek Basch" <dbasch@yahoo.com> wrote:

>  foreach $_ ($self->accessors()) {
>    print "$_\n";
>    my $value = $self->_accessor_class($_)->get($_);
                                        ^^       ^^
                                        ^^       ^^

[snip]

>$self->accessors returns an array of accessor names

So far so fine.

>$self->_accessor_class returns a hash ref to a class

Which happens to be... what?!?
And what does it expect as an argument?

>$self->get returns a scalar value

And what does it expect as an argument?
But most importantly in the code above get() is not a method of $self,
but of the object _accessor_class($_).

All in all it seems *strange*, although not strictly impossible, that
you want to pass $_ to both methods above. Also the fact that
accessors() returns an array of accessor names suggest that you are
fiddling with symrefs. You may return proper $method refs, and call
them like thus instead:

  my $value = $self->$method(...);  

To make a long story short: hard to say anything without looking at
the rest of your code. So, as usual, may you prepare a suitable
minimal but complete example exhibiting the problem? Also you'd better
state more clearly what you're actually trying to do.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 11 Aug 2006 14:22:29 -0700
From: "Derek Basch" <dbasch@yahoo.com>
Subject: Re: Implicit iterator variable $_ changing to ### upon variable assignment?
Message-Id: <1155331349.192507.115250@p79g2000cwp.googlegroups.com>


Derek Basch wrote:
> Derek Basch wrote:
> > Hello all,
> >
> > I have ran into a very confusing problem and I hoped someone could help
> > me. This function is supposed to return a hash of the accessors and
> > their associated values for a given class.
> >
> >
> > ------------------------------------------
> > package Test;
> >
> > sub accessors_values {
> >   my $self = shift;
> >   my %accessors_values;
> >
> >   foreach $_ ($self->accessors()) {
> >     print "$_\n";
> >     my $value = $self->_accessor_class($_)->get($_);
> >     print "$_ : $value\n";
> >   }
> >   return %accessors_values;
> > }
> >
> > ........
> >
> > ------------------------------------------
> >
> > Gives this output:
> > ------------------------------------------
> > password
> > ### : carefree
> > user_id
> > ### : 323227
> > first_login
> > ### : 2006.08.08.12.47.13
> > last_login
> > ### : 2006.08.08.12.47.13
> > ------------------------------------------
> >
> > Where the heck is the '###' coming from? How is assigning a value to
> > the $value variable causing the implicit iterator variable $_ to become
> > '###' ?
> >
> > The functions that the code calls are large so I will give a synopsis
> > of what they return:
> >
> > $self->accessors returns an array of accessor names
> > $self->_accessor_class returns a hash ref to a class
> > $self->get returns a scalar value
> >
> > Any help is greatly appreciated.
> >
> > Thanks,
> > Derek Basch
>
> I answered my own question. The implicit iterator was apparently being
> set to "##" by one of the functions that I called from within the sub.
> I didn't realize that it could be affected in such a way. Live and
> learn I guess.
>
> Thanks Anyways,
> Derek Basch

Note that the way I found this error was by trying to do this:

%accessors_values = map { $iter =>
$self->_accessor_class($iter)->get($iter) } $self->accessors();

The foreach above was my attempt to break the problem into smaller
units for testing.
So, you can solve this problem by not using the implicit iterator with
a foreach loop.

What I didn't mention was that the get function above uses a "while
<FILEHANDLE>"
loop. The "while <FILEHANDLE>" loop uses an implicit iterator and the
map function also uses an implicit iterator.

So, if you use map with an EXPR that uses the "while <FILEHANDLE>"
idiom the map implicit iterator value will be replaced with the "while
<FILEHANDLE>" implicit iterator value. You must use foreach instead of
map.

I hope that helps someone in the future :)

Derek Basch



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

Date: 11 Aug 2006 11:35:04 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: The assignment of command output to an array hangs.
Message-Id: <1155321304.871033.31500@m73g2000cwd.googlegroups.com>

kaleem wrote:
> Hello,
>
> I've got a function in a package which I use to call system commands.
> Inside this function
> I've got the following code:
>
> @results = `$command`; # $command is the system command to run
>
> My problem is that this function (and the piece of code above) works
> fine but it fails for
> a particular command. It just hangs. The command which I'm calling is
> actually a KornShell
> script. I've verified that this script itself does not hang. I tried to
> use -d option to debug and I
> observed that the script hangs at the line shown above. Strangely, when
> I ran the same code
> using 'perl -e' it works! What I did was that I assigned the command to
> $command

How?  Are you confident $command contains what you think it does?

> and then
> just put the same code as shown above. It worked with 'perl -e'.

You're asking us to trust that the code in your file is exactly the
same as the code in your -e'' script.  I don't.   Please post a
short-but-complete script that demonstrates your error.

> Please let me know how can I debug this problem further.

Step one would be printing out $command to verify that it is what you
think it is.  Did you think about newlines and chomping them?  We have
no idea what your actual code is like, so it's nigh impossible to help
you debug it.

Paul Lalli.



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

Date: 11 Aug 2006 11:49:45 -0700
From: "kaleem" <kaleem177@gmail.com>
Subject: Re: The assignment of command output to an array hangs.
Message-Id: <1155322185.074793.249600@b28g2000cwb.googlegroups.com>

Thanks for respoding Paul. Please note that I'm not a novice and I'm
sure of what I'm
saying. I mean I have checked all these things which you are asking me
to check.
Also, on further investigation I've found that after the KornShell
script completes,
it becomes defunct (zombie). It means that its parent hasn't waited for
it. When
I terminate the Perl script, this zombie process goes away.

This is what my code looks like:

cmd ("/abc/xyz/def 2>&1");

/abc/xyz/def is a KornShell script.

The cmd looks like this:

sub cmd
{
     $command = shift;

 ....

     @results = `$command`
 ...

}

Please note that the same code works if I just call /abc/xyz/def using
cmd in
another Perl script or using 'perl -e'. My actual script has lots of
other code in addtition to calling /abc/xyz/def.

Let me know what you think.

Regards,
Kaleem.

Paul Lalli wrote:

> kaleem wrote:
> > Hello,
> >
> > I've got a function in a package which I use to call system commands.
> > Inside this function
> > I've got the following code:
> >
> > @results = `$command`; # $command is the system command to run
> >
> > My problem is that this function (and the piece of code above) works
> > fine but it fails for
> > a particular command. It just hangs. The command which I'm calling is
> > actually a KornShell
> > script. I've verified that this script itself does not hang. I tried to
> > use -d option to debug and I
> > observed that the script hangs at the line shown above. Strangely, when
> > I ran the same code
> > using 'perl -e' it works! What I did was that I assigned the command to
> > $command
>
> How?  Are you confident $command contains what you think it does?
>
> > and then
> > just put the same code as shown above. It worked with 'perl -e'.
>
> You're asking us to trust that the code in your file is exactly the
> same as the code in your -e'' script.  I don't.   Please post a
> short-but-complete script that demonstrates your error.
>
> > Please let me know how can I debug this problem further.
>
> Step one would be printing out $command to verify that it is what you
> think it is.  Did you think about newlines and chomping them?  We have
> no idea what your actual code is like, so it's nigh impossible to help
> you debug it.
> 
> Paul Lalli.



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

Date: 11 Aug 2006 11:54:06 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: The assignment of command output to an array hangs.
Message-Id: <1155322446.511992.124030@m79g2000cwm.googlegroups.com>

kaleem wrote:
> Thanks for respoding Paul. Please note that I'm not a novice and I'm
> sure of what I'm
> saying. I mean I have checked all these things which you are asking me
> to check.
> Also, on further investigation I've found that after the KornShell
> script completes,
> it becomes defunct (zombie). It means that its parent hasn't waited for
> it. When
> I terminate the Perl script, this zombie process goes away.
>
> This is what my code looks like:
>
> cmd ("/abc/xyz/def 2>&1");
>
> /abc/xyz/def is a KornShell script.
>
> The cmd looks like this:
>
> sub cmd
> {
>      $command = shift;
>
> ....
>
>      @results = `$command`
> ...
>
> }
>
> Please note that the same code works if I just call /abc/xyz/def using
> cmd in
> another Perl script or using 'perl -e'. My actual script has lots of
> other code in addtition to calling /abc/xyz/def.
>
> Let me know what you think.

I think you're very arrogant to assume that you have not made any
mistakes, novice or expert.  I asked you to post a short-but-complete
script that we can run to test your problem, and you instead gave me
pseudo code that simply restated what you said in your first post.  You
seem to be wanting us to come back and say "yup, there's a bug in Perl"
rather than to actually help you diagnose what you may have done wrong.

Do you want a solution to your problem, or do you want to avoid
bruising your ego?

Paul Lalli

P.S.  And to those who think this post was rude, yes it was.  But in my
opinion not undeservingly so.



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

Date: 11 Aug 2006 12:05:25 -0700
From: "kaleem" <kaleem177@gmail.com>
Subject: Re: The assignment of command output to an array hangs.
Message-Id: <1155323124.445753.186850@m79g2000cwm.googlegroups.com>

You are crude, Paul. Please don't ever reply to my any further
postings. I never suggested
that Perl had a bug or that I wanted you to come back and tell me that
Perl had a bug. All I
wanted to know was how to debug problem further. If I could provide
code as it is I could
have done it earlier.

Thanks for being so nice.

Paul Lalli wrote:

> kaleem wrote:
> > Thanks for respoding Paul. Please note that I'm not a novice and I'm
> > sure of what I'm
> > saying. I mean I have checked all these things which you are asking me
> > to check.
> > Also, on further investigation I've found that after the KornShell
> > script completes,
> > it becomes defunct (zombie). It means that its parent hasn't waited for
> > it. When
> > I terminate the Perl script, this zombie process goes away.
> >
> > This is what my code looks like:
> >
> > cmd ("/abc/xyz/def 2>&1");
> >
> > /abc/xyz/def is a KornShell script.
> >
> > The cmd looks like this:
> >
> > sub cmd
> > {
> >      $command = shift;
> >
> > ....
> >
> >      @results = `$command`
> > ...
> >
> > }
> >
> > Please note that the same code works if I just call /abc/xyz/def using
> > cmd in
> > another Perl script or using 'perl -e'. My actual script has lots of
> > other code in addtition to calling /abc/xyz/def.
> >
> > Let me know what you think.
>
> I think you're very arrogant to assume that you have not made any
> mistakes, novice or expert.  I asked you to post a short-but-complete
> script that we can run to test your problem, and you instead gave me
> pseudo code that simply restated what you said in your first post.  You
> seem to be wanting us to come back and say "yup, there's a bug in Perl"
> rather than to actually help you diagnose what you may have done wrong.
>
> Do you want a solution to your problem, or do you want to avoid
> bruising your ego?
>
> Paul Lalli
>
> P.S.  And to those who think this post was rude, yes it was.  But in my
> opinion not undeservingly so.

You are crude, Paul. Please don't ever reply to my any further
postings. I never suggested
that Perl had a bug or that I wanted you to come back and tell me that
Perl had a bug. All I
wanted to know was how to debug problem further. If I could provide
code as it is I could
have done it earlier.

Thanks for being so nice. 

Paul Lalli wrote:



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

Date: 11 Aug 2006 12:09:11 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: The assignment of command output to an array hangs.
Message-Id: <1155323350.997301.207180@m79g2000cwm.googlegroups.com>


kaleem wrote:
> You are crude, Paul. Please don't ever reply to my any further postings.

Sorry, you don't get to make that decision.  If you don't want to see
my posts, killfile me.

> I never suggested
> that Perl had a bug or that I wanted you to come back and tell me that
> Perl had a bug. All I
> wanted to know was how to debug problem further.

And I told you exactly how to do that!  You create a short-but-complete
script that exhibits the problem.  If your short-but-complete script
doesn't exhibit the problem, then you figure out what you did
differently between the short script and the "real" script.

> If I could provide code as it is I could have done it earlier.

You could have, but you didn't.  Hence the problem.  You want to know
how to debug your program, but you don't want to actually put any
effort into debugging your program.

Paul Lalli



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

Date: Fri, 11 Aug 2006 19:55:13 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: The assignment of command output to an array hangs.
Message-Id: <Bg5Dg.7499$0e5.2797@newsread4.news.pas.earthlink.net>

On 08/11/2006 01:49 PM, kaleem wrote:
> Thanks for respoding Paul. Please note that I'm not a novice and I'm 
> sure of what I'm 
> saying. I mean I have checked all these things which you are asking me 
> to check.
> Also, on further investigation I've found that after the KornShell 
> script completes, 
> it becomes defunct (zombie). It means that its parent hasn't waited for 
> it. When 
> I terminate the Perl script, this zombie process goes away.
> 
> This is what my code looks like:
> 
> cmd ("/abc/xyz/def 2>&1");
> 
> /abc/xyz/def is a KornShell script.
> 
> The cmd looks like this:
> 
> sub cmd
> {
>      $command = shift;
> 
> .....
> 
>      @results = `$command`
> ....
> 
> }
> 
> Please note that the same code works if I just call /abc/xyz/def using
> cmd in
> another Perl script or using 'perl -e'. My actual script has lots of
> other code in addtition to calling /abc/xyz/def.
> 
> Let me know what you think.
> 
> Regards,
> Kaleem.
> 

Please don't top-post.

Your script is changing the environment such that your "def" 
script won't run correctly. Print out the environment 
variables for both successful and unsuccessful runs and 
compare them.



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

Date: 11 Aug 2006 22:30:36 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: The assignment of command output to an array hangs.
Message-Id: <suppd25vsau08lggcqeod6rtjgrg6mjnpc@4ax.com>

On 11 Aug 2006 12:05:25 -0700, "kaleem" <kaleem177@gmail.com> wrote:

>postings. I never suggested
>that Perl had a bug or that I wanted you to come back and tell me that
>Perl had a bug. All I

It *seemed* so. And Paul told you that it *seemed* so. I agree with
him, and second that.

>wanted to know was how to debug problem further. If I could provide
>code as it is I could
>have done it earlier.

You've not been asked to provide code *as it is*. You've been asked to
take your code and make it into a minimal example exhibiting the
problem. *That* is a way both to debug the problem further and to help
us to help you to debug the problem further.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Fri, 11 Aug 2006 12:16:14 -0700
From: Frank Fredstone <none@not.no>
Subject: win32 sysread on socket hangs when requested == received
Message-Id: <877j1fnkw1.fsf@not.no>

My client blocks if the number of characters sysread reads are the same
as the number requested, e.g.:

my $sock = new IO::Socket::INET (PeerAddr => 'localhost',
                                 PeerPort => "$ARGV[0]",
                                 Proto => 'tcp',
                                );
die "Could not create socket: $!\n" unless $sock;

# the result is the same without the following line
binmode $sock, ':utf8';

$sock->blocking(0);
my $buf = "";
while (1) {
   my $tmp = "";
   my $res = sysread $sock, $tmp, 134;
   printf STDERR "res=%d\n", $res;
   if (defined $res) {
      if ($res < 1) {
         last;
      }
   } elsif ($! == EWOULDBLOCK) {
      next;
   } else {
      die "sysread() error: $!";
   } 
   $buf .= $tmp;
   print STDERR "buf=$buf\n";
   if (length($tmp) < 134) {
      last;
}

With the above code, if 133 or 135 characters are sent by the server,
it works, but if 134 are sent, the next sysread never returns.

The same is true for exact multiples, e.g. if 268 characters are received
with 134 requested, the last sysread hangs.

Do you know a solution to this?



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

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


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