in reply to Best way to "Skip" a set of operations
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.
|
|---|