in reply to Search based on user input and return values
Everything works ok until ... Or is my coding wrong? ... I appreciate for some help/advice.
*cough* subs , more subs, not too many nesting loops, code that compiles, minimal code focusing on the problem , code that doesn't prompt, no weirdo looping constructs, seperate math from mechanics (more subs) ....
same advice How to store the output from foreach loop into variable/array without printing?
If you make named subroutines you can debug the smallest piece(sub) possible, not the whole thing at once in a blender
#!/usr/bin/perl -- ## ## ## perltidy -olq -csc -csci=3 -cscl="sub : BEGIN END " -otr -opr -ce +-nibc -i=4 -pt=0 "-nsak=*" ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr +-ce -nibc -i=4 -pt=0 "-nsak=*" ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if while " -otr + -opr -ce -nibc -i=4 -pt=0 "-nsak=*" #!/usr/bin/perl -- use strict; use warnings; my $massToll = 1; my $timeToll = 2; my @massTime = ( [ 'Mass', 'Time', ], [ '100.20', '0.55', ], [ '150.34', '0.23', ], [ '223.45', '1.22', ], [ '223.44', ], ); my @database = ( [ 'Mass', 'Time', 'Name', 'Type', ], [ '223.41', '1.20', 'John', 'Boy', ], [ '111.23', '5.21', 'Betty', 'Girl', ], [ '100.25', '0.56', 'Ken', 'Boy', ], ); #~ shift @massTime; UnstuckedSmartWay( \@database, $massTime[1], $massToll, $timeToll ); exit( 0 ); sub UnstuckedSmartWayOfSolvingProblems { my( $db, $mtref, $massToll, $timeToll ) = @_; my( $mass, $time ) = @$mtref; for my $row ( @$db ){ my $ret = NaturalIntuitive( $row, $mass, $time, $massToll, $ti +meToll ); } } ## end sub UnstuckedSmartWay sub NaturalIntuitive { my( $row, $mass, $time, $massToll, $timeToll ) = @_; my( $rowMass, $rowTime, $rowName, $rowType ) = @$row; my $math = ...; return $math; } ## end sub NaturalIntuitive __END__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Search based on user input and return values (more subs)
by hellohello1 (Sexton) on Sep 26, 2014 at 03:17 UTC | |
by Anonymous Monk on Sep 26, 2014 at 10:08 UTC | |
by hellohello1 (Sexton) on Oct 15, 2014 at 09:39 UTC | |
by Anonymous Monk on Oct 16, 2014 at 21:38 UTC | |
by hellohello1 (Sexton) on Oct 17, 2014 at 07:46 UTC | |
|