in reply to Inet socket to inet socket communication
Hi QuillMeantTen, I am only addressing your last comment: if you have any suggestions toward making my code more readable/maintainable or at least less eye-gouging ... since you asked.
I would make use of blank lines and spaces and quoted hash key names to improve readability. Of course there's a tradeoff in less code being viewable on a screen, but for me, it's faster to scroll (<CTRL-F>, <CTRL-B> ?) than to try to decipher overly compact source code. My eyes literally don't distinguish the point on the curly brace if it's butted up against a parenthesis. But I'm old. For example I would write:
as this:foreach my $key (@keys){ if(!defined($self->{output}->{$key}->{fh}) && !$self->{output} +->{$key}->{type} eq 'named_pipe'){ croak "undefined fh for key $key\n"; } given($self->{output}->{$key}->{type}){ when('named_pipe'){ open my $handle ,'>',$self->{output}->{$key}->{name} o +r croak "could not open output handle"; print $handle $input; close $handle; } # when ... } }
Alternatively sometimes readability trumps memory usage and I might make a copy of a variable if I was going to be using it a few times, and its current name was unwieldy, especially if that meant I could avoid splitting statements over two lines:foreach my $key ( @keys ) { if ( ! defined ( $self->{'output'}->{$key}->{'fh'} ) && $self->{'output'}->{$key}->{'type'} ne 'named_pipe' ) { croak "undefined fh for key $key\n"; } given ( $self->{'output'}->{$key}->{'type'} ) { when ('named_pipe') { open my $handle, '>', $self->{'output'}->{$key}->{'name'} or croak "open failed: $!"; print $handle $input; close $handle or croak "close failed: $!"; } } }
There you go; this advice is definitely worth what it cost you :-)foreach my $key ( @keys ) { my $foo = $self->{'output'}->{$key}; if ( ! defined $foo->{'fh'} and $foo->{'type'} ne 'named_pipe' ) { croak "undefined fh for key $key\n"; } given ( $foo->{'type'} ) { when ('named_pipe') { open my $handle, '>', $foo->{'name'} or croak "open failed: $! +"; print $handle $input; close $handle or croak "close failed: $!"; } } }
Update: removed a pair of artefactal parens
|
|---|