Taking a step back, having several variables which differ in a suffix is a common red flag that you probably should be using a different data structure. A more common obvious occurrence would be $foo_1, $foo_2, $foo_3, ... which would indicate you may instead want an array @foo. In your case it looks like you should have a hash %UFRAME with references to arrays (aka "HoA"). See perldsc for more details.

That being said were you using a more appropriate data structure your big mess 'o ifs could simplify down into something more like . . .

my $uframe_tilted = undef; my %member_indexen; @member_index{ qw/ x y z Rx Ry Rz / } = ( 3 .. 8 ); if( $input_line =~ /UFRAME/ ) { MEMBERS: for my $member ( qw/ x y z Rx Ry Rz / ) { $UFRAME{$member}->[ $line_array[1] ] = sprintf( "%.3f", $line_array[ $member_index{ $member } ] ) if( $UFRAME{ $member }->[ $line_array[1] ] != 0 ) { $uframe_tilted = 1; last MEMBERS; } } }

Update: Tweaked wording. Also slightly complicating things is that your comparison isn't always ... != 0 but ... == 0 in one case. There's several ways to handle that; one way would be to define a comparison sub that does the right thing based on which hash member you're looking at, then your check would be something like if( _is_frame_tilted( $member, $UFRAME{$member}->{$line_array[1] ) { $uframe_tilted = 1; last MEMBERS; }

sub _is_frame_tilted { my( $member, $value ) = @_; if( $member eq 'Rz' ) { return $value == 0; } else { return $value != 0; } }

The cake is a lie.
The cake is a lie.
The cake is a lie.


In reply to Re: Best way to "Skip" a set of operations by Fletch
in thread Best way to "Skip" a set of operations by thnksnw

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.