[JOB] Perl Software Developer and Database programmer

Robin Barker Robin.Barker at npl.co.uk
Thu Feb 23 11:20:20 GMT 2006

-----Original Message-----
From: Peter Hickman [mailto:peter at semantico.com]
Sent: 23 February 2006 10:57
To: London.pm Perl M[ou]ngers
Subject: Re: [JOB] Perl Software Developer and Database programmer

What was wanted was an optimised version of the original code, that 
means it must produce the same results as the original code. "Hey I've 
optimised the payroll. If you put in more than one expense claim in a 
given period it only pays one of them and ignores the rest" is this "the 
one that's actually wanted".

I think not.

Given that we were not given any such information about the type of data 
that is held in alphas and betas then we cannot ignore the possibility 
of duplicates. We may also be in the position that the order of the 
results is also important so the sorted list with a binary search would 
probably fail for both duplicates and results ordering.
>     foreach my $alpha ( @alphas ) {
>         foreach my $beta ( @betas ) {
>             if ( $alpha == $beta ) {
>                 push @results, $beta;
>             }
>         }
>     }

How about

	my %seen;
	for my $beta ( @betas ) { push @{$seen{$beta + 0}}, $beta; }
	for my $alpha ( @alphas ) {
		if( $seen{$alpha + 0} ) {
			push @results, @{$seen{$alpha + 0}}


 	my %seen;
	for my $beta ( @betas ) { push @{$seen{$beta + 0}}, $beta; }
	push @results, 	
			map { @$_ }
				grep { defined }
					@seen{ map { $_ + 0 } @alphas }


This e-mail and any attachments may contain confidential and/or
privileged material; it is for the intended addressee(s) only.
If you are not a named addressee, you must not use, retain or
disclose such information.

NPL Management Ltd cannot guarantee that the e-mail or any
attachments are free from viruses.

NPL Management Ltd. Registered in England and Wales. No: 2937881
Registered Office: Serco House, 16 Bartley Wood Business Park,
                   Hook, Hampshire, United Kingdom  RG27 9UY

More information about the london.pm mailing list