Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi
I am new to Perl and have just written a script that reads text files from a directory and then sends the data on through a socket connection. It's a very simple process but is very cpu intensive so I suspect my loop and file handling is very flawed. Could someone take a little look at this main loop for me and comment. thanks a lot
the process is 'daemonized' first before entering main loop
opendir DH, "/tmp/store" or die "could not open directory: $!"; while (1) { while($_ = readdir(DH) ) { next if $_ eq "." or $_ eq ".."; my @data = split /_/; $mobile = $data[1]; undef @data; chomp $mobile; s/^\s+//, s/\s+$//, s/\s\s+/ / for $mobile; open FH,"/tmp/sms/$_" or die "could not open: $_ $!"; undef $/; my $data = <FH>; chomp $data; my @fields = split; my $appcode = $fields[0]; my $message = $data; s/^\s+//, s/\s+$//, s/\s\s+/ / for $data; close FH; sendtolive($mobile,$message); # Sends data through socket connecti +on unlink("/tmp/sms/$_"); # remove file once read } } closedir DH;
20031118 Edit by Corion: Added CODE tags, changed title from "cpu intensive"
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: network socket send loop is very cpu intensive
by AcidHawk (Vicar) on Nov 18, 2003 at 12:48 UTC | |
by Anonymous Monk on Nov 18, 2003 at 13:42 UTC | |
by AcidHawk (Vicar) on Nov 18, 2003 at 14:21 UTC | |
by Anonymous Monk on Nov 18, 2003 at 16:16 UTC | |
by AcidHawk (Vicar) on Nov 18, 2003 at 17:37 UTC | |
by l2kashe (Deacon) on Nov 18, 2003 at 21:49 UTC | |
Re: network socket send loop is very cpu intensive
by ptkdb (Monk) on Nov 18, 2003 at 12:51 UTC | |
Re: network socket send loop is very cpu intensive
by Art_XIV (Hermit) on Nov 18, 2003 at 13:54 UTC |
Back to
Seekers of Perl Wisdom