Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Create an array from Optionmenu variables

by shortyfw06 (Beadle)
on Mar 13, 2012 at 14:59 UTC ( #959372=note: print w/ replies, xml ) Need Help??


in reply to Re: Create an array from Optionmenu variables
in thread Create an array from Optionmenu variables

I'm not sure I understand what you're saying?... Let's say I have the following

my $n = 4; my $mat1 = "PW"; my $t1 = "0.0077"; my $ort1 = "45"; my $mat2 = "PW"; my $t2 = "0.0077"; my $ort2 = "45"; my $mat3 = "8HS"; my $t3 = "0.0147"; my $ort3 = "0"; my $mat4 = "PW"; my $t4 = "0.0077"; my $ort4 = "0";

Now I want to sort it as described in the original post. How do I do this efficiently? My first thought would be to write several if statements but I imagine there must be a better way to go about this. Thanks for the help.


Comment on Re^2: Create an array from Optionmenu variables
Download Code
Replies are listed 'Best First'.
Re^3: Create an array from Optionmenu variables
by zentara (Archbishop) on Mar 13, 2012 at 16:53 UTC
Re^3: Create an array from Optionmenu variables
by Anonymous Monk on Mar 13, 2012 at 15:42 UTC

    I'm not sure I understand what you're saying?... Let's say I have the following

    Um, that is not an array, or three arrays, you can't sort that. I too am completely unsure of what you're asking about. Does this help?

    #!/usr/bin/perl -- use strict; use warnings; use Data::Dump; Main( @ARGV ); exit( 0 ); sub Main { my @choice = Ply( 0, 0, 0 ); dd\@choice; push @choice, Ply( 1, 1, 1 ); push @choice, Ply( 2, 2, 3 ); dd\@choice; print "Combinations ", int( @choice ),"\n"; print "Materials ", CountMaterials( \@choice ),"\n"; } sub CountMaterials { my( $co ) = @_; my %seen; for my $item ( @$co ){ my $mat = $item->[0]; $seen{ $mat }++; } return scalar keys %seen; } BEGIN { my @Thickness = ( "0.0077","0.0147","0.0054"); my @Material = ( "PW","8HS","Tape"); my @Orientation = ("-45","0","45","90"); sub Ply { my( $mat, $thi, $ori ) = @_; return [ $Material[ $mat ], $Thickness[ $thi ], $Orientation[ $ori ], ]; } } __END__ [["PW", 0.0077, -45]] [["PW", 0.0077, -45], ["8HS", 0.0147, 0], ["Tape", 0.0054, 90]] Combinations 3 Materials 3

    All you have to do is write a function to query the target option menu and return an array like CountMaterials expects

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2015-07-30 02:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls