[16463] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3875 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 1 18:15:42 2000

Date: Tue, 1 Aug 2000 15:15:28 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <965168128-v9-i3875@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 1 Aug 2000     Volume: 9 Number: 3875

Today's topics:
    Re: Reserved word <chuckwNOchSPAM@silverlink.net.invalid>
    Re: Reserved word <chuckwNOchSPAM@silverlink.net.invalid>
    Re: RSH to os/2 does not work with backticks (Ilya Zakharevich)
    Re: search.cgi   >How do I? <rschram@reed.edu>
    Re: select/vec/pipes question <margit@us.ibm.com>
    Re: select/vec/pipes question <billy@arnis-bsl.com>
    Re: simple perl script for Informix jblatz2@my-deja.com
    Re: splitting on spaces <bdilworth@mco.edu>
    Re: splitting on spaces <dietmar.staab@t-online.de>
        string comparison <gte941n@prism.gatech.edu>
    Re: string comparison <tony_curtis32@yahoo.com>
    Re: string comparison <billy@arnis-bsl.com>
    Re: string comparison <lr@hpl.hp.com>
    Re: string comparison <gte941n@prism.gatech.edu>
        Struct in Perl <gt6786b@prism.gatech.edu>
    Re: Syntax Question <lr@hpl.hp.com>
    Re: Syntax Question (Greg Bacon)
    Re: Syntax Question (Greg Bacon)
    Re: Syntax Question <lr@hpl.hp.com>
    Re: Syntax Question <bardicstorm@my-deja.com>
    Re: Syntax Question <uri@sysarch.com>
    Re: Syntax Question michaeld@brown-cole.com
    Re: Tcl_Panic on Tru64 4.0f ah_changNOSPAM@hotmail.com
        Which Win32 Perl? <iain@kremlinux.demon.co.uk>
        Why does exists($hash{$key}) complain? <phrxy@csv.warwick.ac.uk>
    Re: Why does exists($hash{$key}) complain? (Abigail)
    Re: Why does exists($hash{$key}) complain? <bdilworth@mco.edu>
    Re: Why does exists($hash{$key}) complain? <lr@hpl.hp.com>
    Re: Why does exists($hash{$key}) complain? <billy@arnis-bsl.com>
        XML Parsing problems with <id> tags (Doran)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 01 Aug 2000 14:35:02 -0700
From: chuckw <chuckwNOchSPAM@silverlink.net.invalid>
Subject: Re: Reserved word
Message-Id: <004dd502.31a47c02@usw-ex0104-033.remarq.com>

>>package scrubber;
>>
>>sub new {
>>   my $self;
>>   bless ($self, scrubber);
>
>This is line 6.
>
>>Unquoted string "scrubber" may clash with future reserved word
>>at scrubber.pm line 6.

Well, you got me there. I am completely confused about your
point. What do you mean by "This is line 6"? After that comes
the error message that I saw a zillion times. Don't be so
pedantic as to assume that line number formatting is going to
match up correctly in a usenet post. Please be more specific.
What was your point?


-Chuck



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

Got questions?  Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com



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

Date: Tue, 01 Aug 2000 14:49:18 -0700
From: chuckw <chuckwNOchSPAM@silverlink.net.invalid>
Subject: Re: Reserved word
Message-Id: <08624d7b.355ddcde@usw-ex0104-033.remarq.com>

>== Sorry Abagail, you are wrong. Try it yourself. Create a file
>== named "scrubber.pm" and put the following in it:
>
>
>Which of course has *NOTHING* to do with it being a filename,
or a package
>name. You're using a bareword. Perl warns you about using
barewords,
>unless it starts with a capital letter.
>
>Try this:
>
>#!/opt/perl/bin/perl -w
>
>print STDOUT Foo, "\n"; # No warning!
>print STDOUT foo, "\n"; # Warning!
>__END__
>
>See? No filenames or package names involved.

I think you are contradicting yourself. You wrote this in an
earlier post:

--
Excuse me? If you make a file 'scrubber.pm', "use scrubber;"
will work. There's nothing special about the capatalized file
names.
--

By convention, and for simplicity, I try to keep my class names
the same as the file name (and only one to a file). Until now, I
thought that was the way everyone did it... Apparently not...
Thanks for the help. I learned a lot!

-Chuck


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

Got questions?  Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com



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

Date: 1 Aug 2000 19:46:43 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: RSH to os/2 does not work with backticks
Message-Id: <8m79f3$d8b$1@charm.magnus.acs.ohio-state.edu>

[A complimentary Cc of this posting was sent to 
<tomppa_emoe@my-deja.com>],
who wrote in article <8m6d9i$kp2$1@nnrp1.deja.com>:
> This does not change anything, unfortunately...

Why "unfortunately"?  You know the reason now.  Use Expect (or
substitutions) to open a pTTY instead of a pipe.

Ilya


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

Date: Tue, 01 Aug 2000 12:50:02 -0700
From: RS@ <rschram@reed.edu>
Subject: Re: search.cgi   >How do I?
Message-Id: <10980597.c737ba0a@usw-ex0102-014.remarq.com>

"Rich" <rock.ice@(remove)bigfoot.com> wrote:
>If I add say the second line here for example:
>===============================
>print "Below are your search results:<p></center><hr size=7
>width=75%><p>\n";
>print "<font=arial>\n";
 ..

The user's browser will either break or ignore the output of the
second line. It's not the code that fails, but the HTML.

Try using this instead:

print qq(<FONT FACE="arial, sans-serif">);

as the second line. Also output a closing font tag
(print "</FONT>") somewhere after the script outputs the second
line.




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

Got questions?  Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com



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

Date: Tue, 01 Aug 2000 15:55:03 -0400
From: Margit Meyer <margit@us.ibm.com>
Subject: Re: select/vec/pipes question
Message-Id: <39872B15.168023C6@us.ibm.com>



Ilja Tabachnik wrote:

> Margit Meyer wrote:
> >
> > We have a program which sends off child processes to issue commands or
> > run scripts/programs on other AIX systems. When the program executes
> > from the child process for example "lslpp -l" and then  sleep 20
> > seconds, one line of output is displayed, then the sleep 20 seconds,
> > then the rest of the output. Nothing should be returned until the child
> > process has completed (after the sleep 20 seconds) . We think we have
> > narrowed down where the escapee appears and seems to be caused by a
> > select statement.  Can  someone help with this? The following is sample
> > code where this ocurrs:
> >
> > #Loop while at least one file handle is open
> >   while ($num_fh > 0) {
> > #Wait for outstanding I/O from stdout or stderr
> >    $nready = select($rout = $rin, undef, undef, undef);
> >
> >    last if ($nready == 0);
> >
> > #Data from stdout
> >    if (vec($rout, fileno($ofh), 1)) {
> >        $_ = <$ofh>;
> >        if (length($_)) {
> >            print STDOUT "$hostn: $_";
> >        } else {#EOF has been reached
> >           vec($rin,fileno($ofh),1)=0;
> >           $num_fh-;
>
>             You mean $num_fh-- ?
>
> >        }
> >    }
> > }
> >
>
> Sorry, I really cannot understand what process is the parent,
> what is the child, who is supposed to sleep (and when) and who
> is supposed to print (or to return ?) something.
>
> If you could specify you goals more hm-m... precise,
> I could try to help you.
>
> Good luck.
> Ilja.

Hello,

I specified a snippet of code which performs the print of the stdout received
from the child process. To give you some background, the actual program will
execute on another system scripts or commands native to that system and
return the output to the calling system. For instance, system A invokes a
script which resides on system B containing  ls /tmp; sleep 20; exit 0. Once
the exit is completed the output of the script from system B should be
printed through stdout on system A all at once. This is not the case here.
System A has one line of output printed, through stdout(from the snippet of
code specified), from the script(ls /tmp;sleep 20; exit 0) on system B. Then
the sleep 20 seconds ocurrs on system B from the local script, then the exit
from the local script ocurrs on system B causing the rest of the ls /tmp from
system B to be printed on system A through stdout(again from the snippet of
code). We, my collegues and I, think the line of code:
$nready = select($rout = $rin, undef, undef, undef);
is suppose to wait until the child process has completed (doing the ls /tmp;
sleep 20; exit). Maybe our assumption is incorrect. The stdout is being
printed with the first line of output(from the ls /tmp command on system B)
instead of
waiting until the child process has ended(after the exit on system B)
allowing all the output(from ls /tmp) to be contained in stdout.
The code which we question is:
$nready = select($rout = $rin, undef, undef, undef);
and
if (vec($rout, fileno($ofh), 1))
Maybe someone can explain exactly what the select and vec statements
appear to be doing.
Any advice or help is greatly appreciated.
Thank you.
Margit Meyer



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

Date: Tue, 01 Aug 2000 15:38:00 -0500
From: Ilja Tabachnik <billy@arnis-bsl.com>
Subject: Re: select/vec/pipes question
Message-Id: <39873528.94FCEC67@arnis-bsl.com>

Margit Meyer wrote:
> 
> Ilja Tabachnik wrote:

 ...some code skipped...

> 
> > Sorry, I really cannot understand what process is the parent,
> > what is the child, who is supposed to sleep (and when) and who
> > is supposed to print (or to return ?) something.
> >
> > If you could specify you goals more hm-m... precise,
> > I could try to help you.
> >
> 
> I specified a snippet of code which performs the print of the stdout received
> from the child process. To give you some background, the actual program will
> execute on another system scripts or commands native to that system and
> return the output to the calling system. For instance, system A invokes a
> script which resides on system B containing  ls /tmp; sleep 20; exit 0. Once
> the exit is completed the output of the script from system B should be
> printed through stdout on system A all at once. This is not the case here.
> System A has one line of output printed, through stdout(from the snippet of
> code specified), from the script(ls /tmp;sleep 20; exit 0) on system B. Then
> the sleep 20 seconds ocurrs on system B from the local script, then the exit
> from the local script ocurrs on system B causing the rest of the ls /tmp from
> system B to be printed on system A through stdout(again from the snippet of
> code). We, my collegues and I, think the line of code:
> $nready = select($rout = $rin, undef, undef, undef);
> is suppose to wait until the child process has completed (doing the ls /tmp;
> sleep 20; exit). Maybe our assumption is incorrect. 

Your assumption is incorrect. AFAIK Perl's 4-argument select() does
nothing more
(but no less) than the underlying OS's select(2) system call.
It has nothing to do with wait'ing for a child process to complete.
If you need to wait for a child - use wait() or waitpid().

If all you want is to capture child's stdout and then print it out
(maybe with some processing), you may use open() (to open a pipe)
or backticks.

For more information about IPC solutions:

perldoc perlipc
perldoc perlfaq8
perldoc -f <every_function_you_are_interested_in>

> Maybe someone can explain exactly what the select and vec statements
> appear to be doing.

perldoc -f vec

For select() details see your OS (AIX?) manpage: man select

If perl docs unavailable locally, take a look at
http://www.cpan.org/doc/manual/html/pod/index.html.

BTW, I'm still curious about one hidden detail:
Now do you create a child process on system B from a parent
process on system A :-O

Hope this helps.
Ilja.


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

Date: Tue, 01 Aug 2000 20:46:28 GMT
From: jblatz2@my-deja.com
Subject: Re: simple perl script for Informix
Message-Id: <8m7cv2$e7t$1@nnrp1.deja.com>

You're absolutely right.  I'm all set.

thanks

In article <39869C35.62B64112@transarc.com>,
  jbroz@transarc.com wrote:
> jblatz2@my-deja.com wrote:
> >
> > I just installed DBD::Informix.  I have absolutely no clue how to
run a
> > simple test that will give me some output.
> >
>
> Check the DBI homepage for example programs. Aren't any distributed
with
> the module? There muxt be dozens of examples on the web, have you
looked?
>
> You shouldn't have to know anything about Informix itself. It
understands
> SQL so just send it a few queries. select <x> from <y> where <z> might
be a
> good place to start.
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 01 Aug 2000 16:25:08 -0400
From: Bob Dilworth <bdilworth@mco.edu>
To: emavres@my-deja.com
Subject: Re: splitting on spaces
Message-Id: <39873223.CA4F1197@mco.edu>

Try this:

my $x = "Hello how can    I       help  you";
my $x =~ s/ +//g; # this regex will compress multi spaces to 1 space
my @array = split(/ /,$x);

You should end up with 6 array elements - one for each word.

Bob Dilworth
Toledo, Ohio
bdilworth@mco.edu

ericr@yankthechain.com wrote:

> In article <3985CBA0.73F974@texas.net>,
>   Tom Briles <sariq@texas.net> wrote:
> > ericr@yankthechain.com wrote:
> > >
> > > In article <8m4h6h$9ig$1@nnrp1.deja.com>,
> > >   emavres@my-deja.com wrote:
> > > > Can anyone show me how to split a line that is seperated by
> spaces but
> > > > not by the same amount of spaces?
> > > >
> > > > Example:
> > > >
> > > > "Hello how can    I       help  you"
> > > >
> > > > I would like to get each word.
> > >
> > > split(/ /, $string)); will do that no matter how many space are
> there.
> >
> > Are you sure?  Did you test it?
> >
> > Perhaps you (and the OP) would like to see what the manpage for split
> ()
> > has to say.
> >
> > - Tom
>
> ?
> This works:
> @myarray = split(/ /, $string);
>
> There was a typo with an extra ")", but come on, no one's perfect.
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.



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

Date: Tue, 01 Aug 2000 23:53:29 -0500
From: "Dietmar Staab" <dietmar.staab@t-online.de>
Subject: Re: splitting on spaces
Message-Id: <8m7gri$mud$13$1@news.t-online.com>

In article <39873223.CA4F1197@mco.edu>, Bob Dilworth <bdilworth@mco.edu>
wrote:

Hi Bob,
> Try this:
> 
> my $x = "Hello how can    I       help  you";  my $x =~ s/ +//g; # this

$x =~s/ +/ /g or you will end up with a sentence with no spaces at all and
why declaring the variable twice (with "my")?

> regex will compress multi spaces to 1 space  my @array = split(/ /,$x);
> 
> You should end up with 6 array elements - one for each word.
> 
If you change the right part of the substitution.

But try this string
my $x = "    Hello how can    I       help  you";

I bet you won't get six array elements. ;-)

Greetings, Dietmar


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

Date: 1 Aug 2000 18:21:11 GMT
From: Benjamin David Garrison <gte941n@prism.gatech.edu>
Subject: string comparison
Message-Id: <8m74en$qd8$1@news-int.gatech.edu>

if(substr("$opendate", 1, 6) eq $last_month)

this is always resolving to false....why is that?  (the strings are equal,
but it still resolves to false)  no, there are no newline characters in it
or anything like that...

-- 
Ben Garrison * ICQ#20300203 * IM ben628496 * www.ben.f2s.com
 "Life is short.  Make fun of it."


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

Date: 01 Aug 2000 13:28:28 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: string comparison
Message-Id: <87puns96pf.fsf@limey.hpcc.uh.edu>

>> On 1 Aug 2000 18:21:11 GMT,
>> Benjamin David Garrison <gte941n@prism.gatech.edu> said:

> if(substr("$opendate", 1, 6) eq $last_month) this is
> always resolving to false....why is that?  (the strings
> are equal, but it still resolves to false) no, there are
> no newline characters in it or anything like that...

Since you don't tell anyone what $opendate and $last_month
are, it's impossible to know what the problem is.

hth
t
-- 
"With $10,000, we'd be millionaires!"
                                           Homer Simpson


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

Date: Tue, 01 Aug 2000 13:40:55 -0500
From: Ilja Tabachnik <billy@arnis-bsl.com>
Subject: Re: string comparison
Message-Id: <398719B7.3BE2669B@arnis-bsl.com>

Benjamin David Garrison wrote:
> 
> if(substr("$opendate", 1, 6) eq $last_month)
> 
> this is always resolving to false....why is that?  (the strings are equal,
> but it still resolves to false)  no, there are no newline characters in it
> or anything like that...
> 

Maybe you mean substr($opendate, 0, 6) ?
(you may forget that the first character in $opendate is 
at offset 0, not 1, perldoc -f substr).

Try to print() both to see what's really compared.

Good luck.
Ilja.


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

Date: Tue, 1 Aug 2000 12:12:02 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: string comparison
Message-Id: <MPG.13f0c0de6fbae95f98ac18@nntp.hpl.hp.com>

In article <8m74en$qd8$1@news-int.gatech.edu> on 1 Aug 2000 18:21:11 
GMT, Benjamin David Garrison <gte941n@prism.gatech.edu> says...
> if(substr("$opendate", 1, 6) eq $last_month)
            ^         ^
Those quotes are superfluous and misleading.

> this is always resolving to false....why is that?  (the strings are equal,
> but it still resolves to false)  no, there are no newline characters in it
> or anything like that...

Are you aware that string offsets count from 0, like most else in Perl?

perldoc -f substr

If the strings are equal, as you say, why are you substringing the first 
one, in any case?

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 1 Aug 2000 19:22:35 GMT
From: Benjamin David Garrison <gte941n@prism.gatech.edu>
Subject: Re: string comparison
Message-Id: <8m781r$r42$1@news-int.gatech.edu>

Ilja Tabachnik <billy@arnis-bsl.com> wrote:
> Maybe you mean substr($opendate, 0, 6) ?
> (you may forget that the first character in $opendate is 
> at offset 0, not 1, perldoc -f substr).

<sheepish grin>

-- 
Ben Garrison * ICQ#20300203 * IM ben628496 * www.ben.f2s.com
Eagles may soar, but weasels don't get sucked into jet engines.


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

Date: 1 Aug 2000 20:47:18 GMT
From: Jang Choe <gt6786b@prism.gatech.edu>
Subject: Struct in Perl
Message-Id: <8m7d0m$t6i$1@news-int.gatech.edu>

I'm trying to populate a hash of an array in a "struct" using 
Class::Struct. Let's say I have this struct:

	struct foo => {
		bar => '%',

		# other elements
	};

'bar' is a hash of an array. I tried populating it by:

	my(@stuff) = (1, 2, 3);

	$blah->bar($key, @stuff);

but that didn't work. I get the "Too many args to stuff" error.
So I tried

	$blah->bar($key => [1, 2, 3]);

but this doesn't SEEM to work. I tried to print out the elements of
the array inside the hash and nothing gets printed. So either the
printing the elements of the array doesn't work or the population
doesn't work. Can anyone help? Thank you.


-- 





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

Date: Tue, 1 Aug 2000 11:48:40 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Syntax Question
Message-Id: <MPG.13f0bb5f97c270cf98ac16@nntp.hpl.hp.com>

In article <sodo15h1dbm45@corp.supernews.com> on Tue, 01 Aug 2000 
14:35:17 GMT, Greg Bacon <gbacon@HiWAAY.net> says...
> In article <MPG.13efaf50426d2dcd98ac15@nntp.hpl.hp.com>,
>     Larry Rosler  <lr@hpl.hp.com> wrote:
> 
> : In article <sobr33jt55142@corp.supernews.com> on Mon, 31 Jul 2000 
> : 21:15:15 GMT, Greg Bacon <gbacon@HiWAAY.net> says...

 ...

> : >     my $contents = do { local $/; <FILE> };

 ...

> :       read FILE, $contents, -s FILE or die ...
> 
> It may be fast, but it's incorrect.  What happens when the read is
> incomplete, i.e., when the return value (ignored in this case) is
> less than -s FILE?  Slow and steady wins the race, Mr. Hare.

As was hashed out last time this topic came up, read() is required to 
return the specified number of bytes; returning fewer is a failure, not 
a partial success to be completed by looping over the read().  If you 
are paranoid about such a failure, you can do this:

          my $size = -s FILE;
          $size == read FILE, $contents, $size or die ...

But note carefully that whatever might cause the read() to return 
prematurely would also cause the <FILE> operator to fail prematurely.

          my $contents = do { local $/; <FILE> };
          $contents == -s FILE or die ...

But you didn't do that, nor should you criticize me for not doing it.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Tue, 01 Aug 2000 19:07:57 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Syntax Question
Message-Id: <soe80dchdbm70@corp.supernews.com>

In article <8m71un$59b$1@nnrp1.deja.com>,
     <michaeld@brown-cole.com> wrote:

: [...] I'd like to add, however, that I had a hard time comprehending
: some of the language in the docs and faqs.

Do you have suggestions for how to improve them?  If inaccessibility
is such a big problem, it's something we should really fix.

:                                             What helped my was lurking
: in this newsgroup for a *long* time. [...]

It's unfortunate that most new posters don't bother to lurk at all.
Otherwise, we wouldn't see nearly as many FAQs (or maybe the set of
FAQs would be different).

Greg
-- 
Whenever software asked her whether she was sure she wanted a document
deleted, an operation executed, a session ended, she felt the urge to reply
"No." Yes, she wanted it done, but was she sure? She was never sure of
anything.  -- Jutta Degener


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

Date: Tue, 01 Aug 2000 19:30:55 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Syntax Question
Message-Id: <soe9bferdbm114@corp.supernews.com>

In article <MPG.13f0bb5f97c270cf98ac16@nntp.hpl.hp.com>,
    Larry Rosler  <lr@hpl.hp.com> wrote:

: In article <sodo15h1dbm45@corp.supernews.com> on Tue, 01 Aug 2000 
: 14:35:17 GMT, Greg Bacon <gbacon@HiWAAY.net> says...
:
: > It may be fast, but it's incorrect.  What happens when the read is
: > incomplete, i.e., when the return value (ignored in this case) is
: > less than -s FILE?  Slow and steady wins the race, Mr. Hare.
: 
: As was hashed out last time this topic came up, read() is required to 
: return the specified number of bytes; returning fewer is a failure, not 
: a partial success to be completed by looping over the read().

Where do you see that requirement?  Version 5.6.0 documents read() as
follows:

    =item read FILEHANDLE,SCALAR,LENGTH,OFFSET

    =item read FILEHANDLE,SCALAR,LENGTH

    Attempts to read LENGTH bytes of data into variable SCALAR from the
    specified FILEHANDLE.  Returns the number of bytes actually read,
    C<0> at end of file, or undef if there was an error. [...]

The documentation and your understanding seem to be at odds.  Note the
use of the word 'attempts' used in comparison to what is "actually
read".

:                                                                If you 
: are paranoid about such a failure, you can do this:
: 
:           my $size = -s FILE;
:           $size == read FILE, $contents, $size or die ...

Return values are there for a reason.  Would you dismiss checking
open()'s return value as paranoia?

: But note carefully that whatever might cause the read() to return 
: prematurely would also cause the <FILE> operator to fail prematurely.

Can you please cite a reference in the documentation (or even the
source) that supports your claim?

Greg
-- 
There are better ways to earn a living than to prevent other people from
making use of one's contributions to computer science.
    -- Knuth


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

Date: Tue, 1 Aug 2000 13:35:44 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Syntax Question
Message-Id: <MPG.13f0d47a598e77b798ac1a@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <soe9bferdbm114@corp.supernews.com> on Tue, 01 Aug 2000 
19:30:55 GMT, Greg Bacon <gbacon@HiWAAY.net> says...
+ In article <MPG.13f0bb5f97c270cf98ac16@nntp.hpl.hp.com>,
+     Larry Rosler  <lr@hpl.hp.com> wrote:
+ 
+ : In article <sodo15h1dbm45@corp.supernews.com> on Tue, 01 Aug 2000 
+ : 14:35:17 GMT, Greg Bacon <gbacon@HiWAAY.net> says...
+ :
+ : > It may be fast, but it's incorrect.  What happens when the read is
+ : > incomplete, i.e., when the return value (ignored in this case) is
+ : > less than -s FILE?  Slow and steady wins the race, Mr. Hare.
+ : 
+ : As was hashed out last time this topic came up, read() is required
+ : to return the specified number of bytes; returning fewer is a
+ : failure, not a partial success to be completed by looping over the
+ : read().
+ 
+ Where do you see that requirement?  Version 5.6.0 documents read() as
+ follows:
+ 
+     =item read FILEHANDLE,SCALAR,LENGTH,OFFSET
+ 
+     =item read FILEHANDLE,SCALAR,LENGTH
+ 
+     Attempts to read LENGTH bytes of data into variable SCALAR from
+     the specified FILEHANDLE.  Returns the number of bytes actually
+     read, C<0> at end of file, or undef if there was an error. [...]
+ 
+ The documentation and your understanding seem to be at odds.  Note the
+ use of the word 'attempts' used in comparison to what is "actually
+ read".

See below.  Failure to read what is requested is an error, not a partial 
read.

+ :                                                              If you 
+ : are paranoid about such a failure, you can do this:
+ : 
+ :           my $size = -s FILE;
+ :           $size == read FILE, $contents, $size or die ...
+ 
+ Return values are there for a reason.  Would you dismiss checking
+ open()'s return value as paranoia?

Of course not.  But you clipped my observation that you made no error 
checks on the <FILE> operation.

+ : But note carefully that whatever might cause the read() to return 
+ : prematurely would also cause the <FILE> operator to fail
+ : prematurely.
+ 
+ Can you please cite a reference in the documentation (or even the
+ source) that supports your claim?

The perl source (5.6.0), and the ANSI/ISO C Standard.

In pp_sys.c, PP(pp_read) calls PP(pp_sysread) calls perlIO_read (at line 
1540), which calls fread() (perlio.c, line 368).  The returned value 
gets passed up, and there are no loops.

The ANSI/ISO C Standard says (4.9.8.1):

    The *fread* function returns the number of elements successfully
    read, which may be less than *nmemb* if a read error or end-of-file
    is encountered.

The comment about fread() in the perl source:

	length = PerlIO_read(IoIFP(io), buffer+offset, length);
	/* fread() returns 0 on both error and EOF */
	if (length == 0 && PerlIO_error(IoIFP(io)))
	    length = -1;
    }
    if (length < 0) {
        ... deal with the error ...

is patently incorrect, and the I/O error return isn't analyzed for a 
partial read, but it is an error nevertheless.

So a 'short' read or sysread represents an error, not something that can 
be completed by a subsequent read.

This is my first deep dive into the perl source, and after I catch my 
breath I may file a bug report.  The test at line 1542 should be for any 
length smaller than requested, not just 0.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Tue, 01 Aug 2000 20:35:02 GMT
From: BardicStorm <bardicstorm@my-deja.com>
Subject: Re: Syntax Question
Message-Id: <8m7c9m$dnt$1@nnrp1.deja.com>

In article <soe80dchdbm70@corp.supernews.com>,
  Greg Bacon <gbacon@hiwaay.net> wrote:
> In article <8m71un$59b$1@nnrp1.deja.com>,
>      <michaeld@brown-cole.com> wrote:
>
> : [...] I'd like to add, however, that I had a hard time comprehending
> : some of the language in the docs and faqs.
>
> Do you have suggestions for how to improve them?  If inaccessibility
> is such a big problem, it's something we should really fix.
>
> :                                             What helped my was
lurking
> : in this newsgroup for a *long* time. [...]
>
> It's unfortunate that most new posters don't bother to lurk at all.
> Otherwise, we wouldn't see nearly as many FAQs (or maybe the set of
> FAQs would be different).
>
> Greg
> --
> Whenever software asked her whether she was sure she wanted a document
> deleted, an operation executed, a session ended, she felt the urge to
reply
> "No." Yes, she wanted it done, but was she sure? She was never sure of
> anything.  -- Jutta Degener
>

--
-- The man who worries about what will next be
happening to him loses this moment in dread
of the next, and poisons the next in pre-judgement. --


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 01 Aug 2000 21:25:15 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Syntax Question
Message-Id: <x74s544qth.fsf@home.sysarch.com>

>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:

  LR> The comment about fread() in the perl source:

  LR> 	length = PerlIO_read(IoIFP(io), buffer+offset, length);
  LR> 	/* fread() returns 0 on both error and EOF */
  LR> 	if (length == 0 && PerlIO_error(IoIFP(io)))
  LR> 	    length = -1;
  LR>     }
  LR>     if (length < 0) {
  LR>         ... deal with the error ...

  LR> is patently incorrect, and the I/O error return isn't analyzed for a 
  LR> partial read, but it is an error nevertheless.

  LR> So a 'short' read or sysread represents an error, not something that can 
  LR> be completed by a subsequent read.

  LR> This is my first deep dive into the perl source, and after I catch my 
  LR> breath I may file a bug report.  The test at line 1542 should be for any 
  LR> length smaller than requested, not just 0.

what if you are reading a non-blocking socket? you typically will get a
smaller amount read than you requested. i don't know if that code you
want fixed could handle that properly. IMO perl just passes the
semantics of c's read up the line. <FOO> will cause multiple system
reads to read the whole file any of which could fail. the file might
even be truncated between the last and next read calls, then you could
get a short read.

so let the perl coder handle that as they wish. it is not trivial for
the perl core to know what is a read error based on a short read.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Tue, 01 Aug 2000 21:53:30 GMT
From: michaeld@brown-cole.com
Subject: Re: Syntax Question
Message-Id: <8m7gsp$hc7$1@nnrp1.deja.com>

In article <soe80dchdbm70@corp.supernews.com>,
  Greg Bacon <gbacon@hiwaay.net> wrote:
> In article <8m71un$59b$1@nnrp1.deja.com>,
>      <michaeld@brown-cole.com> wrote:
>
> : [...] I'd like to add, however, that I had a hard time comprehending
> : some of the language in the docs and faqs.
>
> Do you have suggestions for how to improve them?  If inaccessibility
> is such a big problem, it's something we should really fix.

I never really thought about improving them, to be honest.  Whenever I
came across a portion in the packaged docs I had a hard time with, I
always chalked it up to my own lack of experience with perl and I would
consult archived usenet for further information.  When I have problems
comprehending documentation I consider it a shortcoming with my own
experience rather than any failing of the documentation author.
Between archived posts (deja), the official docs, and O'reilly books, I
have a hard time believing that any reasonably motivated perl beginner
couldn't find the information he needed without resorting to a usenet
post.

I usually consult deja first because I can often see the solution to a
programming problem described and written by ten different people at
different levels of language complexity.  I'm impressed that the docs
and faqs also provide multiple solutions to the same problems, but I've
personally had an easier time understanding what I read in this group.

--
--------------------------
michaeld_at_brown-cole.com
binky_at_bingo-lan.org


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 01 Aug 2000 18:33:19 GMT
From: ah_changNOSPAM@hotmail.com
Subject: Re: Tcl_Panic on Tru64 4.0f
Message-Id: <PJEh5.332$0W4.12735@newsread2.prod.itd.earthlink.net>

We are having a problem running Perl/Tk programs on a couple of
machines.  Even with the simplest of programs, including a 'hello world'
I will get the following error. 

GC already registered in Tk_GetGC
Tcl_Panic at /usr/local/lib/perl5/site_perl/Tk/Widget.pm line 188.
at ./hello_world.pl line 5
Tk::Widget::new('Tk::Button', 'MainWindow=HASH(0x14000adf8)', '-text',
'Done', '-command', 
'CODE(0x140112d98)') called at
/usr/local/lib/perl5/site_perl/Tk/Widget.pm line 247
Tk::Widget::__ANON__('MainWindow=HASH(0x14000adf8)', '-text', 'Done',
'-command', 
'CODE(0x140112d98)') called at ./hello_world.pl line 5
at /usr/local/lib/perl5/site_perl/Tk/Widget.pm line 189

I noticed on the README.OSF of Tk800.022 there is the folowing note:
On Alpha if you get something like:

> GC already registered in Tk_GetGC
> Tcl_Panic at ...
>
> Then it has been reported that reducing the optimize from -04 to -03
fixes the problem.

I've tried it by doing 'perl Makefile.PL OPTIMIZE=-03', it gets into the
Makefile, and looks like it is using the correct Optimization during the
make.  But it doesn't fix the problem.

Here are the particulars:
It is happening on a DS20 and ES40 both running Tru64 4.0f with no
patches.  The DS20 has Perl 5.004_04 and the ES40 was upgraded to
5.004_05.  The problem was when it was using Tk400.202 and wasn't fixed
when I tried to upgrade it to Tk800.022.  I tried using Perl 5.6.0, but
that dosen't help either.  The problem dosen't exist on our other DS20's
with Perl 5.004_04 with Tk400.202.  My Hello_world.pl works on these
machines and gets the above error on the problematic machines.  

If anyone can help, I would really appreciate it.  

Kevin

-- 
Kevin Dea

Remove NOSPAM to reply.
But do you really need to reply to me?  Just post it!


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

Date: Tue, 1 Aug 2000 22:27:07 +0100
From: Iain Georgeson <iain@kremlinux.demon.co.uk>
Subject: Which Win32 Perl?
Message-Id: <ZYidRCArC0h5EwXw@kremlinux.demon.co.uk>

[X-posted because I'm after the input of the Tk folks. FU set to .misc]

I'm currently trying out a selection of Perl ports to Win32. I'm after
a port that allows me to use Tk and also build the SNMP module
("build" is an important word there - I'd like to be able to fiddle
with the C source). I'm also considering hacking together the bastard
progeny of the BSD in.tftpd and xsub, so IWBNI that built with
whatever compiler I end up with.

So far, I've played with cygwin 1.1 (which can't build Tk),
mingw32/egcs 2.91.66 (doesn't appear to be able to build SNMP) and
ActiveState (requires me to buy MS Visual C++ and has an obnoxious
redistribution clause).

,--{ActiveState Community License}
| 2. [...] You may not distribute copies of this Package, or copies
| of packages derived from this Package, to others outside your
| organization without specific prior written permission from
| ActiveState (although you are encouraged to direct them to sources
| from which they may obtain it for themselves).
`--

(How does that fit with perl's GPL nature?)

Much as it irks me, it looks like I'll have to use ActiveState Perl and
Microsoft Visual C++, unless you can advise me of another combination
that will do what I need.

Most over-used phrase of the week is

    "This would just plain work on Unix".

        Iain.

-- 
So I think trying to direct Linux is like herding cats. Cats are not
motivated by anything resembling what motivates you, but if you get
enough cats, some portion of them will go the right direction just by
chance.    -- Dave Taylor, responsible for Doom on Linux


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

Date: Tue, 1 Aug 2000 19:46:45 +0100
From: "John J. Lee" <phrxy@csv.warwick.ac.uk>
Subject: Why does exists($hash{$key}) complain?
Message-Id: <Pine.SOL.4.21.0008011905050.10284-100000@mimosa.csv.warwick.ac.uk>


I have a hash %ignore which looks something like the sketch below.  It
has ended up with all keys being integers, so of course it should really
be an array, but I'm puzzled by the exists() behaviour of it.

%ignore:
___________
|key| val |
| 4 | 0   |
| 5 | 5.5 |
| 7 | 0   |
| 8 | -2  |
| 9 | 2   |
-----------

Note the missing entry for the key 6.

The following:
sub foo {
	if (not exists($ignore{$col}) {
		# stuff not involving %ignore goes here
		return $something;
	}
	# stuff involving %ignore goes here
	return $something_else;
}

(where $col == 6), gives me a warning (Use of uninitialised value) with -w
in perl 5.005.  The warning points to the 'if' line.  Why should it warn
me about this when I'm testing exists() precisely so that I can *avoid*
using the uninitialised value?

Thanks for any help


John



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

Date: 01 Aug 2000 16:27:46 EDT
From: abigail@foad.org (Abigail)
Subject: Re: Why does exists($hash{$key}) complain?
Message-Id: <slrn8oecll.vcg.abigail@alexandra.foad.org>

John J. Lee (phrxy@csv.warwick.ac.uk) wrote on MMDXXVII September
MCMXCIII in <URL:news:Pine.SOL.4.21.0008011905050.10284-100000@mimosa.csv.warwick.ac.uk>:
,, 
,, sub foo {
,, 	if (not exists($ignore{$col}) {
,, 		# stuff not involving %ignore goes here
,, 		return $something;
,, 	}
,, 	# stuff involving %ignore goes here
,, 	return $something_else;
,, }
,, 
,, (where $col == 6), gives me a warning (Use of uninitialised value) with -w
,, in perl 5.005.  The warning points to the 'if' line.  Why should it warn
,, me about this when I'm testing exists() precisely so that I can *avoid*
,, using the uninitialised value?


It looks like $col doesn't contain what you think $col contains.


Abigail
-- 
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
                                      print } sub __PACKAGE__ { &
                                      print (     __PACKAGE__)} &
                                                  __PACKAGE__
                                            (                )


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

Date: Tue, 01 Aug 2000 16:15:19 -0400
From: Bob Dilworth <bdilworth@mco.edu>
To: "John J. Lee" <phrxy@csv.warwick.ac.uk>
Subject: Re: Why does exists($hash{$key}) complain?
Message-Id: <39872FD4.D39CC6D0@mco.edu>

John:

Don't know if this'll help but ....

Try using the "defined" operator on the item you want to return instead of
"not exists".  If your thingy is NOT defined then return a null value or a 0
or something that makes sense.
The following is what I had in mind:

sub foo {
        if (defined $ignore{$col})
       {
                # stuff involving %ignore goes here
                return $ignore{$col};
        }
       else
       {
        # stuff not involving %ignore goes here
        return $something_else;
        }
}

As to "why" ...  the old saw:  Ours is not to question why, ours is but blah,
blah ... ;-)

Have fun!!!

Bob Dilworth
Toledo, Ohio
bdilworth@mco.edu

"John J. Lee" wrote:

> I have a hash %ignore which looks something like the sketch below.  It
> has ended up with all keys being integers, so of course it should really
> be an array, but I'm puzzled by the exists() behaviour of it.
>
> %ignore:
> ___________
> |key| val |
> | 4 | 0   |
> | 5 | 5.5 |
> | 7 | 0   |
> | 8 | -2  |
> | 9 | 2   |
> -----------
>
> Note the missing entry for the key 6.
>
> The following:
> sub foo {
>         if (not exists($ignore{$col}) {
>                 # stuff not involving %ignore goes here
>                 return $something;
>         }
>         # stuff involving %ignore goes here
>         return $something_else;
> }
>
> (where $col == 6), gives me a warning (Use of uninitialised value) with -w
> in perl 5.005.  The warning points to the 'if' line.  Why should it warn
> me about this when I'm testing exists() precisely so that I can *avoid*
> using the uninitialised value?
>
> Thanks for any help
>
> John



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

Date: Tue, 1 Aug 2000 13:52:27 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Why does exists($hash{$key}) complain?
Message-Id: <MPG.13f0d86a24c2fdd398ac1b@nntp.hpl.hp.com>

In article <39872FD4.D39CC6D0@mco.edu> on Tue, 01 Aug 2000 16:15:19 -
0400, Bob Dilworth <bdilworth@mco.edu> says...
> John:
> 
> Don't know if this'll help but ....

It won't help at all.  But we might have guessed that from your posting 
a complete copy of the original post, at the end of your response, 
instead of interpolating your comments.  For more detail, search this 
newsgroup for 'Jeopardy'.

> Try using the "defined" operator on the item you want to return instead of
> "not exists".  If your thingy is NOT defined then return a null value or a 0
> or something that makes sense.

The original poster's use of 'exists' is quite correct, and 'defined' 
would produce the same result.  Clearly, the hash key used is undefined, 
so the predicate used to test the hash entry doesn't matter.

> "John J. Lee" wrote:

<Jeopardectomy>

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Tue, 01 Aug 2000 16:12:02 -0500
From: Ilja Tabachnik <billy@arnis-bsl.com>
Subject: Re: Why does exists($hash{$key}) complain?
Message-Id: <39873D22.ACD1C064@arnis-bsl.com>

John J. Lee wrote:
> 
> I have a hash %ignore which looks something like the sketch below.  It
> has ended up with all keys being integers, so of course it should really
> be an array, but I'm puzzled by the exists() behaviour of it.
> 
> %ignore:
> ___________
> |key| val |
> | 4 | 0   |
> | 5 | 5.5 |
> | 7 | 0   |
> | 8 | -2  |
> | 9 | 2   |
> -----------
> 
> Note the missing entry for the key 6.
> 
> The following:
> sub foo {
>         if (not exists($ignore{$col}) {
>                 # stuff not involving %ignore goes here
>                 return $something;
>         }
>         # stuff involving %ignore goes here
>         return $something_else;
> }
> 
> (where $col == 6), gives me a warning (Use of uninitialised value) with -w
> in perl 5.005.  The warning points to the 'if' line.  Why should it warn
> me about this when I'm testing exists() precisely so that I can *avoid*
> using the uninitialised value?
> 

Are you completely sure that $col isn't undefined itself ?

Ilja.


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

Date: Tue, 01 Aug 2000 22:00:42 GMT
From: doran@NOSPAMaltx.net (Doran)
Subject: XML Parsing problems with <id> tags
Message-Id: <3987466b.330317177@news2.brandx.net>

This is an odd one. I have an XML file that I was parsing without
problems. When we altered the file structure a bit, the script broke.
It seems what broke it was the (newly added) tag named <id>. To make
things even stranger, it seems to only break when multiple containers
have this <id> tag. If only one has it, the script doesn't break.

The following example illustrates the problem. It should print out the
index of the last <record> node (in this case "1") but instead it
gives an error. Remove one of the pair of <id> tags and the script
runs fine.

Any ideas?

Thanks,
Doran...


#! /perl/bin/perl -w
use strict;

use XML::Simple;
my $file;
{
local $/='';
$file=<DATA>;
}
my $xml=XMLin("$file");
my $progress = $xml->{dbf}{progress}{record};
print $#$progress;

__END__
<?xml version="1.0" standalone="yes"?>
<escinfo>
	<dbf>
		<progress>
			<record>
				<title>11111</title>
				<id>abcd</id>
			</record>
			<record>
				<title>22222</title>
				<id>efgh</id>
			</record>
		</progress>
	</dbf>
</escinfo>




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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 3875
**************************************


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