PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Tim_Green at mercer dot com
Subject: Off-topic: Perl Question
Date: Jan 14 1998 4:24PM

     (Please forgive the off-topic message.  I'm not aware of a perl list 
     and don't have access to the perl newsgroup.  It is at least a Sybperl 
     application that my problem pertains to. )
     
     --------------------------------------------------------------------
     
     Subject: The socket example in perlipc and why it changed with 5.004
     
     I've always been a bit fuzzy about a few lines of code in the perlipc 
     man page.  I wrote my first socket application (a server) about a year 
     ago and used the simple socket examples in the man page as a starting 
     point.  It worked well, but there are a couple of key lines in the 
     example that I didn't understand and it's come back to haunt me.  
     
     When I upgraded from perl 5.003 to 5.004 my application stopped 
     working, namely ignoring every other message it received.  In 
     attempting to determine what the problem was, I noticed that the man 
     page example that I had drawn so heavily upon had changed in 5.004.  
     When I made a similar change in my application, things worked fine.  
     So, I've got couple questions:
     
     1.  In the code below extracted from the perlipc man page, can someone 
     explain the relationship between the for loop, the reaper function and 
     the $WAITEDPID variable?  Why must $waitedpid be in the for loop's 
     condition?
     
     2.  Why does the example code from 5.003 work in 5.003 but not in 
     5.004?  Or why is the change made in the 5.004 example not necessary 
     in 5.003?
     
     
     Example code from 5.003:
     
01         my $waitedpid = 0;
02         my $paddr;
03
04         sub REAPER {
05             $SIG{CHLD} = \&REAPER;  # loathe sysV 
06             $waitedpid = wait;
07             logmsg "reaped $waitedpid" . ($? ? " with exit $?" : ''); 
08         }
09
10         $SIG{CHLD} = \&REAPER;
11                                                                              
12         for ( $waitedpid = 0;
13              ($paddr = accept(Client,Server)) || $waitedpid; 
14               $waitedpid = 0, close Client)
15         {
16             next if $waitedpid;
17             my($port,$iaddr) = sockaddr_in($paddr); 
18             my $name = gethostbyaddr($iaddr,AF_INET);
           
     
     In the 5.004 example, line 16 is:
               next if $waitedpid and not $paddr;
     
     Thanks in advance for your help,
     
     Tim Green                                           Tim_Green@mercer.com 
     Administrative Solutions Group
     An ADP/Mercer Alliance