#!/usr/bin/perl my $dir = "/tmp/store"; my $sleep = '1'; opendir DH, $dir or die "Opendir $dir: $!\n"; while (1) { for ( grep !/^\.+$/, readdir(DH) ) { my $file = join('/', $dir, $_); # split $_ on _ and return the second element # this avoids a unnecessary temp array my $mobile = ( split /_/ )[1]; # Is the extra whitespace cleanup really necessary? $mobile =~ s/(?:^\s+|\s+$)//g; # drop spaces from front and back $mobile =~ s/\s+/ /g; # sanitize the rest my $old_sep = $/; # being paranoid, save it for later undef $/; open FH, $file or die "open $file: $!\n"; chomp( my $data = ); close FH; $/ = $old_sep; # restore it, in case other funcs expect the default # im not sure what the next few lines are doing, as they are # working on $data or $_, almost randomly. my @fields = split; my $appcode = $fields[0]; # this is never used again? my $message = $data; s/^\s+//, s/\s+$//, s/\s\s+/ / for $data; # should this be $message? sendtolive($mobile, $message); # Sends data through socket connection unlink("$file"); # remove file once read } # END for ( grep readdir(DH) ) closedir(DH); sleep $sleep; } # END while 1