Re: Array subtraction, like sets

2004-01-31 Thread Jeff 'japhy' Pinyan
On Feb 1, Robin Sheat said: >On Fri, Jan 30, 2004 at 10:33:27AM -0500, Jeff 'japhy' Pinyan wrote: >> sub array_diff { >> my ($first, $second) = @_; >> my %diff = map { "@$_" => 1 } @$second; >> return [ map !$diff{"@$_"}, @$first ]; >> } >amended to: >return [ grep !$diff{"@$_"

Re: Array subtraction, like sets

2004-01-31 Thread Robin Sheat
On Fri, Jan 30, 2004 at 10:33:27AM -0500, Jeff 'japhy' Pinyan wrote: > sub array_diff { > my ($first, $second) = @_; > my %diff = map { "@$_" => 1 } @$second; > return [ map !$diff{"@$_"}, @$first ]; > } amended to: return [ grep !$diff{"@$_"}, @$first ]; (for the benefit of any

Re: Array subtraction, like sets

2004-01-30 Thread Robin Sheat
On Fri, Jan 30, 2004 at 10:33:27AM -0500, Jeff 'japhy' Pinyan wrote: > Well, that only works if $a[0] is [1,2,3] and $b[1] is $a[0] -- that is, > the EXACT SAME reference. It won't work if $b[1] is its own [1,2,3]. Hmm, right. Not so good. I had thought of that, and thought I tested it in that si

RE: Array subtraction, like sets

2004-01-30 Thread Bob Showalter
Robin Sheat wrote: > Hey there, what is a nice way of doing what this looks like it should > do: > > @a=([1,2,3],[5,5,5],[9,8,7]); > @b=([5,5,5],[1,2,3]); > @[EMAIL PROTECTED]@b; > > and have @c == ([1,2,3]); > > Is there a good way of doing this? (I've tried the obvious things on > the command

Re: Array subtraction, like sets

2004-01-30 Thread Jeff 'japhy' Pinyan
On Jan 31, Robin Sheat said: >> > @a=([1,2,3],[5,5,5],[9,8,7]); >> > @b=([5,5,5],[1,2,3]); >> > @[EMAIL PROTECTED]@b; ># ># subArray - takes two array references, and subtracts any instances ># of the arrays in the second one from the first one. Returns the new list. >sub subArray { >my @

Re: Array subtraction, like sets

2004-01-30 Thread Robin Sheat
On Fri, Jan 30, 2004 at 07:48:35AM -0700, Wiggins d Anconia wrote: > Going to need more info about what you think this looks like it should > do, because I (and maybe others here) lack the math skills to get your > answer, funny, I got [9,8,7]. Thats what I get for not profraedinng, the result shou

Re: Array subtraction, like sets

2004-01-30 Thread Wiggins d Anconia
> > Hey there, what is a nice way of doing what this looks like it should > do: > Going to need more info about what you think this looks like it should do, because I (and maybe others here) lack the math skills to get your answer, funny, I got [9,8,7]. > @a=([1,2,3],[5,5,5],[9,8,7]); > @b=([5