in reply to Re: Homework question list
in thread Homework question list

Smart people use hash slices. Really smart people use 'undef'd hash slices to save memory.

undef'd hash slices save time not memory.

Update: Also, as pointed out to me in a previous post, only use this method if you don't care about the values of the hash, as the values do not necessarily get set to undef.

Replies are listed 'Best First'.
Re^3: Homework question list
by TomDLux (Vicar) on Oct 29, 2010 at 17:51 UTC

    I notice that in five years no one has filled in the details of the concise implementation.

    # given two arrays you want to compare for common elements, @a1 & @a2 +... my %common; undef @common{@a1}; delete @common{@a2}; my @common = keys %common; #for example: DB<1> @a1 = qw(a b c d e) DB<2> @a2 = qw(a c e ) DB<3> undef @common{@a1} DB<4> x \%common 0 HASH(0x8408418) 'a' => undef 'b' => undef 'c' => undef 'd' => undef 'e' => undef DB<5> delete @common{@a2} DB<6> x \%common 0 HASH(0x8408418) 'b' => undef 'd' => undef DB<7> print join " ", keys %common b d

    As Occam said: Entia non sunt multiplicanda praeter necessitatem.