Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners > Re: how to simp...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 14 Topic 11021 of 11401
Post > Topic >>

Re: how to simplify this script

by rich.japh@[EMAIL PROTECTED] (Richard Lee) May 3, 2008 at 03:17 PM

itshardtogetone@[EMAIL PROTECTED]
 wrote:
> Hi,
> In the script below, I have an array @[EMAIL PROTECTED]
 with its elements consisting
of numbers like this :-
>
> my @[EMAIL PROTECTED]
 = (
>     '1 2 3',  '1 2 4', '1 2 7',  '1 2 8', '1 2 9', '1 6 7',
>     '1 7 12', '2 6 7', '4 5 10', '4 5 15'
> );
>
> Out of the above list, I wish to generate a seperate array so that among
their elements, there should not be any 2 numbers that can match and so the
output should be :-     1 2 3  
>             1 6 7
>             4 5 10
>
> I therefore have written the script below and have tested the script to
be working. What is the easier way to write this script?
> Thanks
>
> ##### start of script ##############
> use strict;
> use warnings;
>
> my @[EMAIL PROTECTED]
 = (
>     '1 2 3',  '1 2 4', '1 2 7',  '1 2 8', '1 2 9', '1 6 7',
>     '1 7 12', '2 6 7', '4 5 10', '4 5 15'
> );
> my $numbers_wanted = 2;
>
> my @[EMAIL PROTECTED]
     = ();
> my $marker         = scalar @[EMAIL PROTECTED]
> my $splice_counter = 0;
> my @[EMAIL PROTECTED]
 = ();
>
> while ($marker) {
>     $splice_counter = 0;
>     push @[EMAIL PROTECTED]
 splice @[EMAIL PROTECTED]
 0, 1;
>     my @[EMAIL PROTECTED]
         = split / /, $datawanted[-1];
>     my $temp_datas_iterator = scalar @[EMAIL PROTECTED]
 - 1;
>
>     foreach ( 0 .. $temp_datas_iterator ) {
>         my $counter     = 0;
>         my @[EMAIL PROTECTED]
 = split / /, $datas[ $_ - $splice_counter ];
>
>         foreach (@[EMAIL PROTECTED]
) {
>             my $a = $_;
>             foreach (@[EMAIL PROTECTED]
) {
>                 if ( $a == $_ ) {
>                     $counter++;
>                 }
>             }
>         }
>         if ( $counter >= $numbers_wanted ) {
>             splice @[EMAIL PROTECTED]
 $_ - $splice_counter, 1;
>             $splice_counter++;
>         }
>     }
>     $marker = scalar @[EMAIL PROTECTED]
> }
>
> foreach (@[EMAIL PROTECTED]
) {
>     print "$_\n";
> }
>
>
>   
I don't have the solution yet but shouldn't the answer be

1 6 7
and
4 5 10 only ?

it's printing out 1 2 3 as well which is wrong?
 




 14 Posts in Topic:
how to simplify this script
itshardtogetone@[EMAIL PR  2008-05-03 21:05:22 
Re: how to simplify this script
rich.japh@[EMAIL PROTECTE  2008-05-03 15:17:13 
Re: how to simplify this script
itshardtogetone@[EMAIL PR  2008-05-04 06:44:18 
Re: how to simplify this script
rich.japh@[EMAIL PROTECTE  2008-05-05 00:31:29 
Re: how to simplify this script
noreply@[EMAIL PROTECTED]  2008-05-05 11:00:28 
Re: how to simplify this script
rich.japh@[EMAIL PROTECTE  2008-05-06 01:25:23 
Re: how to simplify this script
noreply@[EMAIL PROTECTED]  2008-05-06 17:48:51 
Re: how to simplify this script
rich.japh@[EMAIL PROTECTE  2008-05-06 11:56:00 
Re: how to simplify this script
rich.japh@[EMAIL PROTECTE  2008-05-03 15:58:25 
Re: how to simplify this script
noreply@[EMAIL PROTECTED]  2008-05-03 22:22:56 
Re: how to simplify this script
itshardtogetone@[EMAIL PR  2008-05-04 07:03:21 
Re: how to simplify this script
noreply@[EMAIL PROTECTED]  2008-05-04 01:19:40 
Re: how to simplify this script
chas.owens@[EMAIL PROTECT  2008-05-03 21:45:33 
Re: how to simplify this script
chas.owens@[EMAIL PROTECT  2008-05-03 21:51:36 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Jul 6 6:59:00 CDT 2008.