Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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.

In reply to Re: Re: Re: network socket send loop is very cpu intensive by AcidHawk
in thread network socket send loop is very cpu intensive by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (6)
    As of 2021-04-21 09:07 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?