in reply to Socket buffer errors
There's not enough information for me to test your code; however, this condition strikes me as potentially problematic:
index($buf, "/DATA_String/") > 0
In "index STR,SUBSTR,POSITION", the POSITION is zero-based. Perhaps you want:
index($buf, "/DATA_String/") > -1
Consider this code:
$ perl -E ' my @strings = qw{ no_data_string /DATA_String/ X/DATA_String/ /some/path/to/DATA_String/ }; say "-" x 40; for my $string (@strings) { say "\$string[$string]"; for my $pos (qw{0 -1}) { say "\$pos[$pos]"; if (index($string, "/DATA_String/") > $pos) { say "index() TRUE"; } else { say "index() FALSE"; } } say "-" x 40; } '
Output:
---------------------------------------- $string[no_data_string] $pos[0] index() FALSE $pos[-1] index() FALSE ---------------------------------------- $string[/DATA_String/] $pos[0] index() FALSE $pos[-1] index() TRUE ---------------------------------------- $string[X/DATA_String/] $pos[0] index() TRUE $pos[-1] index() TRUE ---------------------------------------- $string[/some/path/to/DATA_String/] $pos[0] index() TRUE $pos[-1] index() TRUE ----------------------------------------
"I am new to socket programming but found an example in O’Reilly’s “Advanced Perl Programming”. After adjusting the code for my network, ..."
"Advanced Perl Programming" is an excellent book, I own a copy myself; however, it was published over a quarter of a century ago. Here's some suggestions for aligning your code with modern practices:
So, your code might become something like this:
... use strict; use warnings; use autodie; use IO::Socket; { open my $pid_fh, '>', '/var/run/aws.rcvr.pid'; print $pid_fh "$$\n"; } my ($sock, $new_sock, $buf ); $sock = IO::Socket::INET::->new(...); ...
— Ken
|
|---|