[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] sifting



2000-04-12-14:53:33 Peter Scott:
> Hafta think of this one as a pattern too :-)

Another approach, which appeals to me a bit more, would be like

	my @input = qw(Every
	                ALPHA_male
	                Good
	                Boy
	                BETA_blocker
	                Deserves
	                ALPHA_BETA
	                Fine
	                ALPHA_channel
	                BETA_Max
	                Apples);

	my @categories = qw(ALPHA BETA);
	my @rejects;

	my($pat) = qr(@{[join('|', @categories)]});

	my %cats;
	/($pat)/ ? push @{$cats{$1}}, $_ : push @rejects, $_ for @input;
	my @results;
	push @results, @{$cats{$_}} for @categories;
	push @results, @rejects;
	print "@results\n";

Another design pattern.

-Bennett

PGP signature