Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Count of element in array - Help

by jwkrahn (Abbot)
on Feb 22, 2021 at 04:33 UTC ( [id://11128646]=note: print w/replies, xml ) Need Help??


in reply to Count of element in array - Help

For what it's worth, I made the code more Perlish and incorporated the fix proposed by the others:

use strict; use warnings; system 'cls'; Menu_Main( 10 ); sub Menu_Main { my ( $SWOS ) = @_; #$arr = Text to display, Menu position/selection#, Menu Section, +Numerical Reference my @arr = sort { $a->[ 1 ] <=> $b->[ 1 ] || $a->[ 2 ] <=> $b->[ 2 +] } $SWOS == 10 ? [ 'First', 8, 1, 27 ] : (), $SWOS == 10 ? [ '5x First', 13, 2, 28 ] : (), $SWOS == 10 ? [ 'Second', 9, 1, 29 ] : (), $SWOS == 10 ? [ 'Third', 10, 1, 30 ] : (), $SWOS == 10 ? [ '8x- Fourth', 21, 3, 31 ] : (), $SWOS == 10 ? [ '5x- Fifth', 17, 2, 32 ] : (), $SWOS == 10 ? [ '8x- First', 18, 3, 33 ] : (), $SWOS == 10 ? [ '8x- Second', 19, 3, 34 ] : (), $SWOS == 10 ? [ '5x- Fourth', 16, 2, 35 ] : (), $SWOS == 10 ? [ '8x- Third', 20, 3, 36 ] : (), $SWOS == 10 ? [ '5x- Second', 14, 2, 37 ] : (), $SWOS == 10 ? [ 'XXX- First', 23, 4, 38 ] : (), $SWOS == 10 ? [ 'Fouth', 11, 1, 39 ] : (), $SWOS == 10 ? [ 'Fifth', 12, 1, 40 ] : (), $SWOS == 10 ? [ '8x- Fifth', 22, 3, 41 ] : (), $SWOS == 10 ? [ '5x- Third', 15, 2, 42 ] : (); my @menu = ( '', '5x & 8x Series', '5x Series', '8x Series', 'Othe +r' ); my $menuidx = 1; print 'Select [1-' . @arr . "].\n\n$menu[$menuidx]\n"; for my $i ( 0 .. $#arr ) { if ( $arr[ $i ][ 2 ] != $menuidx ) { print "\t\t", '-' x 58, "\n$menu[$arr[$i][2]]\n"; $menu = $arr[ $i ][ 2 ]; } #print "\t\t$arr[$i][1]. $arr[$i][0]\n"; print "\t\t", $i + 1, ". $arr[$i][0]\n"; } print 'Selection ==> '; chomp( my $ANS = <STDIN> ); if ( $ANS < 1 || $ANS > @arr ) { warn "$ANS is not a valid menu selection.\n"; return; } # Print elements in array print 'Array count #1: ' . @arr . " \nProcessing ANS: $ANS\n"; my $MMANS = $arr[ $ANS - 1 ][ 3 ]; # Print Elements in array again print 'Array count #2: ' . @arr . " \nMMANS is: $MMANS\n"; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-25 12:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found