reading line from socket

C

cerr

Hi There,

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

John W. Krahn

cerr said:
Hi There,

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

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




John
 
W

Willem

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

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

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

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


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

sln

Hi There,

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

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

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

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

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

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

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

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

Likewise, a test in any code flow:

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

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


Read perlfunc on defined()

-sln
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top