f77coder has asked for the wisdom of the Perl Monks concerning the following question:
Hello.
Am looking for some opinions on how to write these operations.
@array1A=qw(a b c d); @array1B=qw(p z e t i u); @array_of_arrays=(@array1A, @array1B, @array2A,@array2B…@arrayNA,@arra +yNB);
sub arrays have different lengths have unique values and don't want to sort them. I want so sort the array_of_arrays based on following
1. sort array based on number of elements in each from smallest to largest
2. is it possible to sort the sub-arrays by name? then size?
3. to do a random sort by name with (1A,2A…) then (1B,2B,…). Example
@array_of_arrays=(@array2A,@array4A,@array1A,…@array1B,@array5B);the interesting part is the operations on the sub arrays, I do search of each sub array with a scalar value. the following loop has no sorting .
while (<DATA>){ chomp; my @element = split; my $i1=shift @element; my $i2=shift @element; my $i3=shift @element; my $i4=shift @element; shift @element; shift @element; my $i7=shift @element; if(any{ $_ eq $i1} @array1A)) {print 'yes'; }elsif((any{ $_ eq $i1} @array1B)) {print 'no'; }elsif((any{ $_ eq $i2} @array2A)) {print 'yes'; }elsif((any{ $_ eq $i2} @array2B)) {print 'no'; }else{print "WTF";} };
I need the If loop rearranged based on the order of the array_of_arrays Is this possible?
All help is appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: multiple array processing
by AnomalousMonk (Archbishop) on Sep 03, 2014 at 03:22 UTC | |
by f77coder (Beadle) on Sep 03, 2014 at 04:44 UTC | |
by AnomalousMonk (Archbishop) on Sep 03, 2014 at 05:52 UTC | |
by f77coder (Beadle) on Sep 06, 2014 at 23:28 UTC | |
by NetWallah (Canon) on Sep 03, 2014 at 05:16 UTC | |
by f77coder (Beadle) on Sep 06, 2014 at 23:25 UTC | |
|
Re: multiple array processing
by AppleFritter (Vicar) on Sep 03, 2014 at 10:15 UTC | |
by f77coder (Beadle) on Sep 07, 2014 at 00:02 UTC | |
by AnomalousMonk (Archbishop) on Sep 07, 2014 at 00:44 UTC |