http://qs321.pair.com?node_id=307979


in reply to Re: Re: network socket send loop is very cpu intensive
in thread network socket send loop is very cpu intensive

No problem, I like to have one exit point also, so I put this little bit together to illustrate the point...

This is UNTESTED though..

#! /usr/bin/perl use strict; use warnings; my $rc = 0; while (1) { if (opendir DH, "/tmp/store") { if (readdir(DH) ) { next if $_ eq "." or $_ eq ".."; my @data = split /_/; my $mobile = $data[1]; undef @data; chomp $mobile; s/^\s+//, s/\s+$//, s/\s\s+/ / for $mobile; if (open FH,"/tmp/store/$_") { undef $/; my $data = <FH>; chomp $data; my @fields = split; my $appcode = $fields[0]; my $message = $data; #Assuming you want to clean up the data that is being +sent to sendtolive() s/^\s+//, s/\s+$//, s/\s\s+/ / for $message; close FH; # Sends data through socket connection assuming the se +ndtolive returns a success or fail # you can test for it and only delete if it is success +ful. Do you want to delete the file if it cant send the sms..? if (sendtolive($mobile,$message)) { # remove file once read unlink("/tmp/store/$_"); } else { print "Count NOT sent $message: sendtolive failed" +; } } else { print "could not open: $_ $!"; $rc = 3; last; } } else { print "Cannot read dir /tmp/store: $!\n"; $rc = 2; last; } #You have finished with this file loop onto the next. closedir (DH); sleep(1); } else { print "Faile to open dir /tmp/store: $!\n"; $rc = 1; last; } } exit ($rc);

-----
Of all the things I've lost in my life, its my mind I miss the most.