Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I couldn't agree more with you. For instance, take the following function I wrote:

for ( @status ) { my $pass = 0; chomp; # eliminate that nasty terminator! :) $_ =~ s/\0//; # Ignore the stuff that comes from this # command for now. Maybe later I will # use this information for something but # I will wait until a more mature release # of this code. if ( $watch ) { # I know this next section looks obfuscated # but actually, it was the easiest way for me # to accomplish my task here. # This block takes data that looks like this: # # player name number number # IPaddr number number <- one record # player name number number # IPaddr number number <- another record # # and parses out just the name per record # so that the array is now propagated with # player name <- from reocrd 1 # player name <- from record 2 # etc. # NOTE to self: You will probably need to get # the IP address at some point here! $pass = 1 if $pass == 0; $pass = 2, $_ =~ s/( .*).*// if $pass; $pass = 1 # place regex to extract IP here if $pass == 2; push( @player_info, $_ ) if $_; } # start counting after we see the "-"'s $watch = 1 if ( /-/ ); } if ( $#player_info >= 0 ) { return($#player_info + 1); } else { return(0); } }
Notice the lil block of if statements?

$pass = 1 if $pass == 0; $pass = 2, $_ =~ s/( .*).*// if $pass; $pass = 1 # place regex to extract IP here if $pass == 2; push( @player_info, $_ ) if $_;

To me this seemed to be a much simpler block of code to write while at the same time not too difficult to understand what it was doing. Consider the alternative:

A rough estimation of the translation of the above code (untested)...

if ( $pass == 0 ) { $pass = 1; } elsif ( $pass ) { $pass = 2; $_ =~ s/( .*).*//; } elsif ( $pass == 2 ) { $pass = 1; } if ( $_ ) { push( @player_info, $_ ); }

I'd be curious to know what others think.
I wonder if I could have used the flip-flop operator here.

- Jim

In reply to Re: Re: Perverse Unreadable Code by snafu
in thread Perverse Unreadable Code by Anonymous Monk

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    [atcroft]: Lady_Aleena: I found the L<name|section> syntax, which describes linking to a perl manual page, and L<text|url> to link to a web page. The reason I asked was because I was on looking at a module,
    [atcroft]: and it referred to several other modules, but the links went to I found that a bit of a surprise, and it got me wondering if there was a "standard" way to link to other modules in the documentation on CPAN.
    [Lady_Aleena]: atcroft. maybe look at raw PODs. There is also L<foo|http://foo. com> and some might be linking directly to meta::cpan.
    [Lady_Aleena]: Oops, didn't read the L<text|url> right.

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (3)
    As of 2017-05-27 03:54 GMT
    Find Nodes?
      Voting Booth?