[ale] UNIX Question

Wandered Inn esoteric at denali.atlnet.com
Tue Dec 1 07:38:29 EST 1998


Stan.Hearn at ipst.edu wrote:
> 
> I've got two lists:
> 
> LARGE="aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk"
> SMALL="aaa ccc ddd eee fff ggg"
> 
> Solution: DIFF="bbb hhh iii jjj kkk"
> 
> I want to know which items in LARGE are not in SMALL.  I want to calculate
> DIFF.
> 
> SMALL will always be a subset of LARGE.  In other words, no value in SMALL
> would not exist in LARGE.
> 
> I can think of a couple of ways to get this to work, but they all seem to
> be very kludgey.  I know this is an easy problem for perl, but this piece
> is part of a larger /bin/sh script.
> 
> Does a method for determining this pop into your head?
> 
> STAN

Quick shot at this, seems to work...


#!/usr/bin/perl -w

use strict;

my @L= qw(aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk);
my @S= qw(aaa ccc ddd eee fff ggg);
my $foo; my $bar;

loop:
foreach $foo (@L) {

	foreach $bar (@S) {

		if ($bar eq $foo) { next loop; }
	}

	printf "%s\n", $foo;

}


--
Until later: Geoffrey		esoteric at denali.atlnet.com

You mean you paid MONEY for Service Pack '98????






More information about the Ale mailing list