Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Re: Perverse Unreadable Code

by snafu (Chaplain)
on Jul 06, 2001 at 23:07 UTC ( #94562=note: print w/ replies, xml ) Need Help??


in reply to Re: Perverse Unreadable Code
in thread Perverse Unreadable Code

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


Comment on Re: Re: Perverse Unreadable Code
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://94562]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (16)
As of 2014-12-18 16:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (58 votes), past polls