It's hazardous to your health to refactor code without test data, but I've asked a similar question in the past, so here's my attempt.

I'm not sure about the math in the condition if( @cur_spin == ( $row_length + 15 ) ) {, which I why I left it there rather than folding it into the constant at the top. It seems to me that every time you use the $row_length constant, you then add 15 more items to @cur_spin anyway. So factoring that out, by adding 15 to the constant and always add the 15 items reduces the clutter--but I'd need to test it to convince myself that I did it correctly.

Copying all the data to a temp array and then having to reference the slice [ 3.. 17 ] in 3 different places seems clumsy. If you need to use the temp array, better to only copy the slice you are going to need, and then use it all each time. Of course that would translate the magic [3] into the magic [ 0 ].

Two locally scoped variables called $major_frame_index & $minor_frame_index represent multiple instances of 12 redundant characters, long, ugly lines and no gain in clarity.

You seem to be uncomfortable with using @array in a scalar context as the size of the array, which is quite common, but how could the size of the array ever be negative in my $cur_spin_cnt = (scalar @cur_spin > 0) ? scalar @cur_spin : 0?

Update: Added the missing first line that went walkabout when C&Ping.

sub WriteSpinData { my( $OUT_FH, $ref ) = @_; my( $last_major, $line, @cur_spin ); my( $row_length ) = 15*160+1; for my $filename ( sort keys %{ $ref } ) { for my $major ( sort keys %{ $ref->{$filename} } ) { for my $minor ( grep{/^\d+$/} keys %{ $ref->{$filename}{$m +ajor} } ){ @cur_spin = "$filename,$major,$minor" if $ref->{$filename}{$major}{$minor}[ 3 ] == 165 and ( $minor % 10 ) == 0; push @cur_spin, @{ $ref->{$filename}{$major}{$minor} } +[ 3..17 ]; if( @cur_spin == ( $row_length + 15 ) ) { print $OUT_FH join( ',', @cur_spin ), "\n"; @cur_spin = (); } } $last_major = $major; } printf "%s: %d major frames\n", basename( $filename ), $last_m +ajor; } }

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: Refactoring nested if block by BrowserUk
in thread Refactoring nested if block by bowei_99

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.