[30786] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2031 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 4 18:09:44 2008

Date: Thu, 4 Dec 2008 15:09:10 -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           Thu, 4 Dec 2008     Volume: 11 Number: 2031

Today's topics:
        a simple control in an nntp client <george@example.invalid>
    Re: dynamic name of a variable in a class sln@netherlands.com
    Re: dynamic name of a variable in a class xhoster@gmail.com
    Re: how detect english subject and predicate in a sente <jack_posemsky@yahoo.com>
    Re: how detect english subject and predicate in a sente <jack_posemsky@yahoo.com>
    Re: how detect english subject and predicate in a sente <RedGrittyBrick@spamweary.invalid>
    Re: how detect english subject and predicate in a sente <tzz@lifelogs.com>
    Re: how detect english subject and predicate in a sente <sbryce@scottbryce.com>
    Re: how detect english subject and predicate in a sente <cwilbur@chromatico.net>
    Re: Mathematica 7 compares to other languages <malkia@mac.com>
    Re: Mysql -> Perl - MS-Excel ? damjensen@gmail.com
    Re: Problem with call to system(), I think. sln@netherlands.com
        sysread and syswrite analogy xhoster@gmail.com
    Re: sysread and syswrite analogy <jimsgibson@gmail.com>
    Re: Web programming: issues with large amounts og data sln@netherlands.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 4 Dec 2008 14:13:27 -0700
From: George <george@example.invalid>
Subject: a simple control in an nntp client
Message-Id: <dihweb43hc6x.dumxmx7ft1vp$.dlg@40tude.net>


I would like to extend the following script:

#!/usr/bin/perl -w

use strict;
use Net::NNTP ();

use constant NUMBER_OF_ARTICLES    => 10;
use constant GROUP_NAME        => 'alt.solaris.x86';
use constant SERVER_NAME    => 'news.individual.net';
use constant NNTP_DEBUG        => 0;

my $nntp = Net::NNTP->new(SERVER_NAME, 'Debug' => NNTP_DEBUG) or die;
my $USER = '';
my $PASS = '';

$nntp->authinfo($USER,$PASS) or die $!;


my($article_count, $first_article, $last_article) =
$nntp->group(GROUP_NAME) or die;


# Which XOVER fields contain Subject: and From:?
my $count = 0;
my %xover_fmt = map( ($_, $count++), @{ $nntp->overview_fmt or die} );
die unless exists $xover_fmt{'Subject:'};
my $subject_offset = $xover_fmt{'Subject:'};
my $from_offset = $xover_fmt{'From:'};

my(@xover, $start_article);
RETRIEVE: while ($#xover+1 < NUMBER_OF_ARTICLES and $last_article >=
$first_article) {

    # How many articles do we need?  Stop retrieving if we have enough
    my $articles_required = NUMBER_OF_ARTICLES - ($#xover+1) or last
RETRIEVE;


    # Fetch overview information for the articles
    $start_article = $last_article - ($articles_required-1);
    $start_article = $start_article > $first_article ? $start_article :
$first_article;

    my $xover_query = $start_article == $last_article ?
    $start_article :
    [$start_article, $last_article];
    my $xover_ref = $nntp->xover($xover_query) or die;

    # Store headers for the articles we've retrieved
    foreach (sort {$b <=> $a} keys %$xover_ref) {
        push @xover, $xover_ref->{$_};
    }
} continue {
    # Move the pointer forward to fetch previous articles
    $last_article = $start_article - 1;
}

# Disconnect from the NNTP server
$nntp->quit;

print join("\n", map ($_->[$subject_offset].' from '.$_->[$from_offset],
@xover)),"\n";


#  perl script1.pl 2>text50.txt >text51.txt

Current output is:

C:\MinGW\source>perl script1.pl
Re: Solaris 10 update 6 on Intel x86. from CJT <abujlehc@prodigy.net>
Re: Solaris 10 update 6 on Intel x86. from Ian Collins
<ian-news@hotmail.com>
Re: Solaris 10 update 6 on Intel x86. from Atiqur Rahman <Unix9N@gmail.com>
Re: Solaris 10 update 6 on Intel x86. from Ian Collins
<ian-news@hotmail.com>
Re: Solaris 10 update 6 on Intel x86. from Atiqur Rahman <Unix9N@gmail.com>
Re: Solaris 10 update 6 on Intel x86. from Atiqur Rahman <Unix9N@gmail.com>
Re: Solaris 10 update 6 on Intel x86. from Atiqur Rahman <Unix9N@gmail.com>
Re: Solaris 10 update 6 on Intel x86. from jones.tim.l@gmail.com
Solaris 10 update 6 on Intel x86. from Atiqur Rahman <Unix9N@gmail.com>
Re: Booting multi-user but w/o X from jones.tim.l@gmail.com

C:\MinGW\source>

The way I would like to extend this is the following:

If the article is from 'Atiqur Rahman', then I would like to print the
entire article.

This may sound trivially easy to those with more experience with perl.  I
find the control structures very difficult in perl.  I've done similar
things before, but it's been a while since I've used perl.  I have
_Programming Perl_ as a reference.

Thanks for your comment.

-- 
George

We will stand up for our friends in the world. And one of the most
important friends is the State of Israel. My administration will be
steadfast in support Israel against terrorism and violence, and in seeking
the peace for which all Israelis pray.
George W. Bush

Picture of the Day http://apod.nasa.gov/apod/


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

Date: Thu, 04 Dec 2008 20:57:35 GMT
From: sln@netherlands.com
Subject: Re: dynamic name of a variable in a class
Message-Id: <asggj4d4ee1ildh9d3viqsbfnubg8k91p6@4ax.com>

On Thu, 4 Dec 2008 07:11:51 -0600, Tad J McClellan <tadmc@seesig.invalid> wrote:

>Brownie <brownie2002@gmail.com> wrote:
>
>
>> I know that my request is ugly, 
>
>
>Do you mean that you have already read the FAQ answer for your question?
>
>    How can I use a variable as a variable name?
>
>
>> but I need tot do that.
>
>
>You only _think_ you need to do that.
>
>Using a more appropriate data structure would avoid needing to use
>symbolic references.
>
[snip]
>> dice_axis($epoch->{SOL_$SOLUTION_A}->{XYZ},1,$k3-1) .= $sol
>                     ^^^^^^^^^^^^^^^
>> $SOLUTION_temp[$k];
>
>
>Hash keys are auto-quoted for you only if they are bare words.
>
>If they are not bare words, then you need to quote the hash keys yourself:
>
>    dice_axis($epoch->{"SOL_${SOLUTION}_A"}...
>or, the somewhat uglier:
>    dice_axis($epoch->{'SOL_' . $SOLUTION . '_A'}...
>
This works as well:
    dice_axis($epoch->{"SOL_$SOLUTION\_A"}...



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

Date: 04 Dec 2008 21:37:35 GMT
From: xhoster@gmail.com
Subject: Re: dynamic name of a variable in a class
Message-Id: <20081204163634.487$Li@newsreader.com>

Brownie <brownie2002@gmail.com> wrote:

> so in the main i have :
> [...]
> dice_axis($epoch->{SOL_L1_A}->{XYZ},1,$k3-1) .= $solL1_temp[$k];

So dice_axis is an l-value subroutine?

> $SOLUTION = L1;

L1 probably needs quotes.

> dice_axis($epoch->{SOL_$SOLUTION_A}->{XYZ},1,$k3-1) .=
> $sol$SOLUTION_temp[$k];

Solving your "variable in a class" problem is trivial.

$epoch->{SOL_${SOLUTION}_A}

The real problem is with @solL1_temp and kin.  But you didn't show us the
part of the code that declares and defines those, so you you didn't show us
the part of the code that created the real problem.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

Date: Thu, 4 Dec 2008 11:40:39 -0800 (PST)
From: Jack <jack_posemsky@yahoo.com>
Subject: Re: how detect english subject and predicate in a sentence
Message-Id: <2fe31759-65d5-40c4-90da-bd12226bb6f2@t39g2000prh.googlegroups.com>

On Dec 4, 8:34=A0am, Ted Zlatanov <t...@lifelogs.com> wrote:
> On Wed, 3 Dec 2008 21:49:14 -0800 (PST) Jack <jack_posem...@yahoo.com> wr=
ote:
>
> J> Hi there, just checking to see if anyone knows how to perform this
> J> basic grammar function ? =A0I searched CPAN and found nothing that was
> J> able to in Perl..
>
> If you can limit the input, you're better off. =A0IOW, make your input
> conform to some basic templates and then guess from that template.
> Otherwise you won't solve it with CPAN, although there are quite a few
> commercial NLP products.
>
> What is your real goal? =A0Are you trying to find something in the text,
> or accept input to tell you what to do, or analyzing it statistically,
> or something else? =A0Each one of those has a specific set of solutions w=
e
> can recommend, but there's no generic solution. =A0Language is just too
> complex. =A0Don't forget people can use bad grammar, malformed sentences,
> misspell, and use English dialects or made-up words.
>
> Ted

Thanks all.

I want to know the topical NOUN of the sentence.  Not nouns that
happen to supplement elsewhere in the sentence.  In "fruit flies like
a banana" - the key or topical noun is 'fruit' NOT banana yet both are
nouns...just 1 example.  It should answer which noun reveals the focal
point, indicating what the sentence is about (fruit in the above
case).  Does that make sense.

Thank you,
Jack


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

Date: Thu, 4 Dec 2008 11:43:38 -0800 (PST)
From: Jack <jack_posemsky@yahoo.com>
Subject: Re: how detect english subject and predicate in a sentence
Message-Id: <86a7fd6a-9899-47b7-a769-c4ffb70315a0@a37g2000pre.googlegroups.com>

On Dec 4, 11:40=A0am, Jack <jack_posem...@yahoo.com> wrote:
> On Dec 4, 8:34=A0am, Ted Zlatanov <t...@lifelogs.com> wrote:
>
>
>
>
>
> > On Wed, 3 Dec 2008 21:49:14 -0800 (PST) Jack <jack_posem...@yahoo.com> =
wrote:
>
> > J> Hi there, just checking to see if anyone knows how to perform this
> > J> basic grammar function ? =A0I searched CPAN and found nothing that w=
as
> > J> able to in Perl..
>
> > If you can limit the input, you're better off. =A0IOW, make your input
> > conform to some basic templates and then guess from that template.
> > Otherwise you won't solve it with CPAN, although there are quite a few
> > commercial NLP products.
>
> > What is your real goal? =A0Are you trying to find something in the text=
,
> > or accept input to tell you what to do, or analyzing it statistically,
> > or something else? =A0Each one of those has a specific set of solutions=
 we
> > can recommend, but there's no generic solution. =A0Language is just too
> > complex. =A0Don't forget people can use bad grammar, malformed sentence=
s,
> > misspell, and use English dialects or made-up words.
>
> > Ted
>
> Thanks all.
>
> I want to know the topical NOUN of the sentence. =A0Not nouns that
> happen to supplement elsewhere in the sentence. =A0In "fruit flies like
> a banana" - the key or topical noun is 'fruit' NOT banana yet both are
> nouns...just 1 example. =A0It should answer which noun reveals the focal
> point, indicating what the sentence is about (fruit in the above
> case). =A0Does that make sense.
>
> Thank you,
> Jack- Hide quoted text -
>
> - Show quoted text -

In other words, step 1 in the process to me is - "what" is it we are
talking about ?  This is the most basic question.  "What" is the noun
subject of the sentence?  Step 2 being, descriptive support,
adjectives, etc. about "it".  Just trying to get to step 1 !


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

Date: Thu, 04 Dec 2008 19:58:03 +0000
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: how detect english subject and predicate in a sentence
Message-Id: <gh9coe$r5$1@news.motzarella.org>


Jack wrote:
> On Dec 4, 8:34 am, Ted Zlatanov <t...@lifelogs.com> wrote:
>> On Wed, 3 Dec 2008 21:49:14 -0800 (PST) Jack <jack_posem...@yahoo.com> wrote:
>>
>> J> Hi there, just checking to see if anyone knows how to perform this
>> J> basic grammar function ?  I searched CPAN and found nothing that was
>> J> able to in Perl..
>>
>> If you can limit the input, you're better off.  IOW, make your input
>> conform to some basic templates and then guess from that template.
>> Otherwise you won't solve it with CPAN, although there are quite a few
>> commercial NLP products.
>>
>> What is your real goal?  Are you trying to find something in the text,
>> or accept input to tell you what to do, or analyzing it statistically,
>> or something else?  Each one of those has a specific set of solutions we
>> can recommend, but there's no generic solution.  Language is just too
>> complex.  Don't forget people can use bad grammar, malformed sentences,
>> misspell, and use English dialects or made-up words.
>>
>> Ted
> 
> Thanks all.
> 
> I want to know the topical NOUN of the sentence.  Not nouns that
> happen to supplement elsewhere in the sentence.  In "fruit flies like
> a banana" - the key or topical noun is 'fruit' NOT banana yet both are
> nouns... 

How about "flies" as a plural noun?


> just 1 example.  It should answer which noun reveals the focal
> point, indicating what the sentence is about (fruit in the above
> case).  Does that make sense.

Not to me.

http://www.skotos.net/articles/dawnof15.shtml

-- 
RGB
Gabrielle’s *father* is an axe-murderer
Anteaters *father* attractive offspring
Wendy’s *father* country is Iceland


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

Date: Thu, 04 Dec 2008 14:15:59 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: how detect english subject and predicate in a sentence
Message-Id: <86bpvrofwg.fsf@lifelogs.com>

On Thu, 4 Dec 2008 11:40:39 -0800 (PST) Jack <jack_posemsky@yahoo.com> wrote: 

J> On Dec 4, 8:34 am, Ted Zlatanov <t...@lifelogs.com> wrote:
>> What is your real goal?  Are you trying to find something in the text,
>> or accept input to tell you what to do, or analyzing it statistically,
>> or something else?  Each one of those has a specific set of solutions we
>> can recommend, but there's no generic solution.  Language is just too
>> complex.  Don't forget people can use bad grammar, malformed sentences,
>> misspell, and use English dialects or made-up words.

J> I want to know the topical NOUN of the sentence.  Not nouns that
J> happen to supplement elsewhere in the sentence.  In "fruit flies like
J> a banana" - the key or topical noun is 'fruit' NOT banana yet both are
J> nouns...just 1 example.  It should answer which noun reveals the focal
J> point, indicating what the sentence is about (fruit in the above
J> case).  Does that make sense.

No, I understand that your immediate technical goal is to find the noun.
Your wider goal seems to be the topic of the sentence.

I'm asking why you want to find the noun/topic.  What will you do with
this information?  Is it a *command* or a *source of statistics* or a
*classification* or something else?  Any one of those things has
specific ways to be done we can recommend rather than solving the
immediate technical goal, which as several have mentioned is very
difficult.

Ted


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

Date: Thu, 04 Dec 2008 14:09:39 -0700
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: how detect english subject and predicate in a sentence
Message-Id: <gh9gul$e9o$1@news.motzarella.org>

Jack wrote:
> I want to know the topical NOUN of the sentence.  Not nouns that 
> happen to supplement elsewhere in the sentence.  In "fruit flies like
> a banana" - the key or topical noun is 'fruit' NOT banana yet both
> are nouns...just 1 example.

This is an example which points out how difficult the task is. "Fruit"
is NOT the topic of the sentence. "flies" is. "Fruit" tells us what type
of flies like bananas.

If YOU cannot determine the subject of the sentence, how do you expect
to write code that determines the subject of the sentence?


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

Date: Thu, 04 Dec 2008 17:10:19 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: how detect english subject and predicate in a sentence
Message-Id: <86k5af7fsk.fsf@mithril.chromatico.net>

>>>>> "SB" == Scott Bryce <sbryce@scottbryce.com> writes:

    SB> Jack wrote:

    >> I want to know the topical NOUN of the sentence.  Not nouns that
    >> happen to supplement elsewhere in the sentence.  In "fruit flies
    >> like a banana" - the key or topical noun is 'fruit' NOT banana
    >> yet both are nouns...just 1 example.

    SB> This is an example which points out how difficult the task
    SB> is. "Fruit" is NOT the topic of the sentence. "flies"
    SB> is. "Fruit" tells us what type of flies like bananas.

Actually, the sentence can be read *correctly* in two incompatible ways.
You can read "Fruit flies" as the subject, and "like a banana" as the
predicate, or "Fruit" as the subject, and "flies like a banana" as the
predicate.  Both readings are correct.

Structurally, it's identical to the former sentence in the statement:
"Time flies like an arrow."  But because there is no such thing as a
"time fly," there's only one reading that makes sense.

In other words, you can't determine what the subject of the sentence is
without knowledge of the semantic content.  

    SB> If YOU cannot determine the subject of the sentence, how do you
    SB> expect to write code that determines the subject of the
    SB> sentence?

This is, at its heart, the fundamental question.

Charlton


-- 
Charlton Wilbur
cwilbur@chromatico.net


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

Date: Thu, 04 Dec 2008 12:08:48 -0800
From: "Dimiter \"malkia\" Stanev" <malkia@mac.com>
Subject: Re: Mathematica 7 compares to other languages
Message-Id: <gh9dch$6un$1@news.motzarella.org>

> You think the posts are bad... check out his web site...

Just don't go to every page on the Xah website - some of his stuff is 
NSFW (Not Safe For Work).


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

Date: Thu, 4 Dec 2008 11:24:51 -0800 (PST)
From: damjensen@gmail.com
Subject: Re: Mysql -> Perl - MS-Excel ?
Message-Id: <26537b56-1a61-4332-a1a6-07ed2805fafd@k8g2000yqn.googlegroups.com>

Actually, there is (yet) another path. Ready for the big secret.. ?
Excel can
read from SQL directly ! Yes, you can actually do this directly with a
few lines of VBA scripting,
some ODBC connection and a button press.

This has the added bonus that Excel can (somewhat itelligently) read
the data format from the database,
so it will get the dates, numbers, decimals etc right.

And, of course, that you can make it dynamic and make an online
selection of what you need, to create different
data each time.

This should guide you:
http://www.dicks-clicks.com/excel/ExternalData.htm



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

Date: Thu, 04 Dec 2008 20:00:34 GMT
From: sln@netherlands.com
Subject: Re: Problem with call to system(), I think.
Message-Id: <r6dgj4pvohno745kjv6qsjbaknggca31ic@4ax.com>

On Thu, 04 Dec 2008 10:42:41 -0600, Ted Zlatanov <tzz@lifelogs.com> wrote:

>On 03 Dec 2008 22:53:28 GMT Leon Timmermans <fawaka@gmail.com> wrote: 
>
>LT> On Tue, 02 Dec 2008 17:47:31 +0000, sln wrote:
>>> @args = (
>>> "activity.report.1.pl",
>>> "\"$merchant\"",
>>> $merchants_usernames{$merchant},
>>> $merchants{$merchant},
>>> $date_string,
>>> "1>$dir\\activity.Report.$merchant.stdout",
>>> "2>$dir\\activity.Report.$merchant.stderr",
>>> );
>>> 
>
>LT> Those last few arguments wouldn't work well. It's probably best to use 
>LT> something like IPC:Open3 here.
>
>IPC::Run is also good, although the docs are a bit confusing.
>
>Ted

I posted an arglist with each one quoted. That is the correct fix with one
small change. I didn't see the redirect parameters.

Below does both show the real problem(s) in 'Consideration #1 and #2' and
the fix in 'Consideration #3 and #4'.

There is only one problem when the OP gets 'used by another  process' message.
No need to do IPC:Open3 unless this doesen't work. But I've got money say's this
is the actual fix for his/her problem.

Unfortunately, he/she has opened another thread on this with a different angle
trying to fix the same problem, and he/she will never read this.

Good luck!


sln

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

Command line:
____________________________
c:\temp>perl ttt.pl

Consideration #1:
---------------------------
The process cannot access the file because it is being used by another process.
problem with jjj.pl: 256

Consideration #2:
---------------------------

Consideration #3:
---------------------------
Consideration #4:
---------------------------

c:\temp>

____________________________________________________________

ttt.pl:
-----------------------------------------
use strict;
use warnings;

my @args;
my $dir = "c:\\temp";
my $merchant = "Home Depot";

my %merchants = ($merchant => 'home depot');
my %merchants_usernames = ($merchant => 'H DEPOT');
my $date_string = "Jan 1, 2009";

print "Consideration #1:\n---------------------------\n";
system("perl jjj.pl \"$merchant\" $merchants_usernames{$merchant} $merchants{$merchant} $date_string 1>$dir\\activity.Report.$merchant.stdout1 2>$dir\\activity.Report.$merchant.stderr1") == 0
    or warn "problem with jjj.pl: $?\n";

print "\nConsideration #2:\n---------------------------\n";
@args = (
  'jjj.pl',
  "\"$merchant\"",
  $merchants_usernames{$merchant},
  $merchants{$merchant},
  $date_string,
  "1>\"$dir\\activity.Report.$merchant.stdout2\"",
  "2>\"$dir\\activity.Report.$merchant.stderr2\"",
);
system("perl @args") == 0 or warn "problem with jjj.pl: $?";

print "\nConsideration #3:\n---------------------------\n";
@args = (
  'jjj.pl',
  "\"$merchant\"",
  "\"$merchants_usernames{$merchant}\"",
  "\"$merchants{$merchant}\"",
  "\"$date_string\"",
  "1>\"$dir\\activity.Report.$merchant.stdout3\"",
  "2>\"$dir\\activity.Report.$merchant.stderr3\"",
);
system("perl @args") == 0 or warn "problem with jjj.pl: $?";


print "Consideration #4:\n---------------------------\n";
system("perl jjj.pl \"$merchant\" \"$merchants_usernames{$merchant}\" \"$merchants{$merchant}\" \"$date_string\" 1>\"$dir\\activity.Report.$merchant.stdout4\"
2>\"$dir\\activity.Report.$merchant.stderr4\"") == 0
    or warn "problem with jjj.pl: $?\n";




jjj.pl:
-----------------------------------------
use strict;
use warnings;

for (@ARGV) {
	print "$_\n";
}


activity.Report.Home:
-------------------------------------


activity.Report.Home Depot.stdout2:
--------------------------------------
Home Depot
H
DEPOT
home
depot
Jan
1,
2009


activity.Report.Home Depot.stdout3:
activity.Report.Home Depot.stdout4:
---------------------------------------
Home Depot
H DEPOT
home depot
Jan 1, 2009








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

Date: 04 Dec 2008 19:58:16 GMT
From: xhoster@gmail.com
Subject: sysread and syswrite analogy
Message-Id: <20081204145716.083$RZ@newsreader.com>

For file handles that don't have O_NONBLOCK turned on, I see this
behavior:

sysread will return partial reads (fewer bytes than were requested), rather
than blocking, provided that the partial read is at least one byte.

syswrite will not perform partial writes, but rather it will block waiting
for the entire write to be accepted.

Based on sysread's behavior, I would have expected syswrite to return
immediately with a partial write, provided that at least one character was
written.  Why the lack of analogy between the two?

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

Date: Thu, 04 Dec 2008 14:00:38 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: sysread and syswrite analogy
Message-Id: <041220081400384454%jimsgibson@gmail.com>

In article <20081204145716.083$RZ@newsreader.com>, <xhoster@gmail.com>
wrote:

> For file handles that don't have O_NONBLOCK turned on, I see this
> behavior:
> 
> sysread will return partial reads (fewer bytes than were requested), rather
> than blocking, provided that the partial read is at least one byte.

Check "Advanced Programming in the Unix Environment", R. Stevens., p.
54. The Unix read system call operating in blocked mode will return
fewer than the number of bytes requested if:

1. File I/O: only the last record.
2. Terminal I/O: returns on end-of-line
3. Network I/O: returns if network can't supply bytes in reasonable
time.
4. Device I/O: device is record-oriented.

> 
> syswrite will not perform partial writes, but rather it will block waiting
> for the entire write to be accepted.

Well you are operating in blocked mode, so it should block. So the
question should be "why does read not always block", and the exceptions
as listed above seem reasonable.

> 
> Based on sysread's behavior, I would have expected syswrite to return
> immediately with a partial write, provided that at least one character was
> written.  Why the lack of analogy between the two?

I think that one basic difference is that for a read, you do not know
how many bytes are being made available. For a write, you know exactly
how many bytes are available for writing.

If the system were to only accept some of your bytes, you would have to
save the unwritten bytes and try to write them again, which is what
happens for non-blocking writes.

For input, it makes sense to return fewer bytes in those cases where
blocking would be unreasonable (stalled network I/O or record-oriented
data.)

For output, it doesn't make much sense to only accept a partial write
and return, because the program will usually just try to write the
unwritten bytes again, so the system call may as well block. It makes
more sense to use the select function to make sure that the output
stream is ready to accept output, and try to use a buffer size
sufficient to accept most output records.

-- 
Jim Gibson


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

Date: Thu, 04 Dec 2008 20:14:14 GMT
From: sln@netherlands.com
Subject: Re: Web programming: issues with large amounts og data
Message-Id: <j3egj4t7789t716cofdqhd6hq3co2kdlct@4ax.com>

On Wed, 3 Dec 2008 23:33:43 -0800 (PST), Ted Byers <r.ted.byers@gmail.com> wrote:

>On Dec 4, 12:09 am, Tim Greer <t...@burlyhost.com> wrote:
>> Ted Byers wrote:
>> > The problem manifests itself as the download terminating and the
>> > script appearing to freeze.
>>
>> There can be a number of reasons for this.  Please post the relevant
>> portions of the (Perl) code.  This might not be a perl code issue.
>> --
>> Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
>> Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
>> and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
>> Industry's most experienced staff! -- Web Hosting With Muscle!
>
>Hi Tim,
>
>Thanks.
>
>Here is a simple program that shows this problem:
>
>use strict;
>use XML::Twig;
>use DBI;
>use IO::File;
>use POSIX qw(strftime);
>use Text::ParseWords;
>use LWP::RobotUA;
>use LWP::UserAgent;
>use HTTP::Request;
>use HTTP::Request::Common;
>use HTTP::Response;
>use Date::Manip;
>
>Date_Init("TZ=EST5EDT");
>
>my $affiliate;
>my $merchant;
>my $uid;
>my $pwd;
>my $opfile;
>
>my $db='test';
>my $hostname = 'localhost';
>my $port = '3306';
>my $user = 'xxxxxxx';
>my $dbpwd = 'yyyyyyyyyyy';
>
>my $dbh = DBI->connect("DBI:mysql:database=$db;host=$hostname",
>                    $user, $dbpwd, {RaiseError => 1});
>
>my $uri = "https://our.datafeed.site/query.php";
>my $req_url;
>#my $ua = LWP::UserAgent->new;
>
>my $now_string = strftime "%a %b %d %Y Generic", localtime;
>mkdir "$now_string";
>chdir "$now_string";
>
>my $start_date = $ARGV[0];
>my $end_date = $ARGV[1];
>
>my $query = "SELECT merchant_name, uid, pwd FROM merchants WHERE
>is_active = 1";
>
>my $sth = $dbh->prepare($query)          or die $dbh->errstr;
>$sth->execute();
>while (my $ref = $sth->fetchrow_hashref()) {
>  $merchant = $ref->{'merchant_name'};
>  $uid = $ref->{'uid'};
>  $pwd =  $ref->{'pwd'};
>  $req_url = "$uri?username=$uid&password=$pwd&start_date=
>$start_date&end_date=$end_date";
>  STDOUT->print($req_url);STDOUT->print("\n\n");
>  $opfile = "$uid.xml";
>  STDOUT->print($opfile);STDOUT->print("\n");

>  system("..\\generic_download_child.pl $uid \"$req_url\" 1>
>$uid.stdout 2>$uid.stderr");

You should get out of the habit of passing unquoted "$variables" to
the command shell, even if you know they don't need quotes.

  system("..\\generic_download_child.pl \"$uid\" \"$req_url\" 1>\"$uid.stdout\" 2>\"$uid.stderr\"");
                                        ^^    ^^ ^^        ^^   ^^           ^^   ^^

sln



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

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


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