Hi Light-Angel,

Before I even try to figure out what your error is, I want to suggest you consider refactoring your code, at least in future programs.

Edit: I see you're using POE modules, which I don't use, nor have installed. I'll take a few more minutes to see if I spot anything, but I'm afraid I won't be able to run this.

For example, doing this:

if (...) { if (...) { if (...) { if (...) { .... } else { return 0; } } else { return 0; } } else { return 0; } } else { return 0; }
Is simply unreadable. And my example only goes to 4 levels; your code goes to 7!

If you reverse the logic, and do the return 0 blocks first, it's a heck of a lot easier to read and maintain:

($msg =~ /^([^\s]+)/) or return 0; $alias = $1; ($msg =~ /-address="([^"]+)"/) or return 0; $address = $1; ($msg =~ /-port="([^"]+)"/) or return 0; $port = $1; ($msg =~ /-nick="([^"]+)"/) or return 0; $nick = $1; ($msg =~ /-password="([^"]+)"/) or return 0; $password = $1; ($msg =~ /-prefix="([^"]+)"/) or return 0; $prefix = $1; ($msg =~ /-auto_connect="([^"]+)"/) or return 0; $auto_connect = $1;

You could even take it a step further, and make it data-driven. It's not as short as the first rewrite, but it has the advantage of grouping functionality together, so you can see what's being matched all in one section, and what's being assigned to in another section:

# Regular expressions to apply my $a_regexes = [ qr/^([^\s]+)/, qr/-address="([^"]+)"/, qr/-port="([^"]+)"/, qr/-nick="([^"]+)"/, qr/-password="([^"]+)"/, qr/-prefix="([^"]+)"/, qr/-auto_connect="([^"]+)"/, ]; # Construct an array of resulting regex captures my @results = ( ); # Save each pattern (returning if missing from regex) foreach my $regex (@$a_regexes) { if ($msg !~ /$regex/) { return 0; } push @results, $1; } # Assign to the desired variables my ($alias, $address, $port, $nick, $password, $prefix, $auto_connect) = @results;

Update 2:

Here's an even terser suggestion for capturing the tokens, since (other than the first regex) they all have the same essential format. Define the list of tokens to capture, and build each regex from that:

# Define the tokens we wish to extract my @tokens = qw( address port nick password prefix auto_connect ); # First token is a special case my $alias = ($msg =~ /^(\S+)\s*/)? $1: ""; $alias or return 0; # Construct an array of resulting regex captures my @results = ( ); # Construct the regex from each token, and capture the value foreach my $token (@tokens) { ($msg =~ /-${token}="([^"]+)"/ or return 0; push @results, $1; } # Assign to the desired variables my ($address, $port, $nick, $password, $prefix, $auto_connect) = @r +esults;
say  substr+lc crypt(qw $i3 SI$),4,5

In reply to Re: Passing message between 2 sockets by golux
in thread Passing message between 2 sockets by Light-Angel

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.