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:

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 ... } }
as this:
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: $!"; } } }
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 ) { 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: $!"; } } }
There you go; this advice is definitely worth what it cost you :-)

Update: removed a pair of artefactal parens

The way forward always starts with a minimal test.

In reply to Re: Inet socket to inet socket communication by 1nickt
in thread Inet socket to inet socket communication by QuillMeantTen

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, details, 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, summary, 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.