From: cerr on 7 Apr 2010 14:31 Hi There, I'm using something like: if (defined(<SOCKET>)) { while (($line = <SOCKET>) && $count < $POSLIMIT){ .... .... and i'm getting following: "Value of <HANDLE> construct can be "0"; test with defined() at ./ UpdateServer.pl line 831." How can i get rid of this message? Thank you! -- roN
From: John W. Krahn on 7 Apr 2010 14:34 cerr wrote: > Hi There, > > I'm using something like: > if (defined(<SOCKET>)) > { > while (($line = <SOCKET>) && $count < $POSLIMIT){ > ... > ... > and i'm getting following: > "Value of <HANDLE> construct can be "0"; test with defined() at ./ > UpdateServer.pl line 831." > How can i get rid of this message? Thank you! while (defined($line = <SOCKET>) && $count < $POSLIMIT){ John -- The programmer is fighting against the two most destructive forces in the universe: entropy and human stupidity. -- Damian Conway
From: Willem on 7 Apr 2010 15:30 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
From: Tad McClellan on 7 Apr 2010 17:31 Willem <willem(a)turtle.stack.nl> wrote: > cerr wrote: > ) Hi There, > ) > ) I'm using something like: > ) if (defined(<SOCKET>)) > > This reads a line from the socket and then throws it away. That's sure enough true. > Is this what you want ? > > ) { > ) while (($line = <SOCKET>) && $count < $POSLIMIT){ > > If $count >= $POSLIMIT, then this reads a line from the socket > and then throws it away. Is this what you want ? If $count >= $POSLIMIT, then this reads a line from the socket and terminates the while loop. The data is still safely tucked into $line. Is that what the OP wants? -- Tad McClellan email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/" The above message is a Usenet post. I don't recall having given anyone permission to use it on a Web site.
From: sln on 7 Apr 2010 17:41 On Wed, 7 Apr 2010 11:31:22 -0700 (PDT), cerr <ron.eggler(a)gmail.com> wrote: >Hi There, > >I'm using something like: > if (defined(<SOCKET>)) > { > while (($line = <SOCKET>) && $count < $POSLIMIT){ >... >... >and i'm getting following: >"Value of <HANDLE> construct can be "0"; test with defined() at ./ >UpdateServer.pl line 831." >How can i get rid of this message? Thank you! Krahn showed the fix for you. This is a FAQ somewhere. $line is evaluated as a conditional. It is the result of the <HANDLE> read operation. The read could return a '0' or 0, which equals false in a conditional and breaks out of the loop. In terms of defined(), all things are defined unless its variable has the UNDEF flag set via some way, $line = undef is one way. The sucess of a call is usually returned via undef. Since there is only 1 definition of undef, most functions sneek it in on failure, otherwise the test is on the data returned. Adding a defined(($line = <SOCKET>)) around this really checks if the read succeded or did not. At EOF, it will return undef. These are mostly the built-in functions that return undef as a special meaning. Sometimes its a pain to have to use the defined check all the time though. In general, asignments within conditionals can be tricky. The trick is to know if undef as a return value is a factor in the code flow. Likewise, a test in any code flow: $line = <HANDLE>; if (defined( $line)) { # do other checks # do something with line, its valid data } else { # $line is undef, HANDLE is at eof } if (defined (0) and not 0) # true if (defined ("0") and not "0") # true if (defined ("") and not "") # true Read perlfunc on defined() -sln
|
Pages: 1 Prev: Correct way to save zip file after replacing member? Next: FAQ 1.8 Is Perl difficult to learn? |