in reply to Mostly Harmless

Hello emdub, and welcome to the Monastery!

Here is one way to do this (for a single pair of lines):

#! perl use strict; use warnings; my $string1 = 'CHARLIE ROOT'; my $string2 = 'HARRY NODE'; my @list1 = split //, $string1; my @list2 = split //, $string2; my %hash1 = map { $_ => undef } @list1; my %hash2 = map { $_ => undef } @list2; delete $hash1{' '}; delete $hash2{' '}; for (@list1) { print unless exists $hash2{$_}; } for (@list2) { print unless exists $hash1{$_}; }

Output:

16:26 >perl 815_SoPW.pl CLI TY ND 16:26 >

There are no doubt more elegant/streamlined approaches, but this should give you an idea. (Extending the script to read and compare lines from the two files is left as an exercise!)

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Mostly Harmless
by atcroft (Abbot) on Dec 28, 2013 at 08:06 UTC

    Here is another approach (again, for one pair of words, so extending would be an exercise for the reader):

    use strict; use warnings; my $str1 = q{CHARLIE ROOT}; my $str2 = q{HARRY NODE}; my $output = process( $str1, $str2 ) . q{ } . process( $str2, $str1 ); print $output, qq{\n}; sub process { my ( $word1, $word2 ) = @_; my @letters_to_remove = grep{ ! m/\s+/; } split //, $word2; my $remove_str = join q{}, q{[}, @letters_to_remove, q{]}; my $result = $word1; $result =~ s/$remove_str//g; return $result; }

    Output:

    CLI T Y ND

    In this code, a character group is constructed on the fly, and a substitution operation replaces each member globally in the string with nothing, removing the character. (The string is not as efficient as it could be, since it may contain repeated characters, but this was off-the-cuff code, so there we are.)

    Hope that helps-if not in usefulness, then at least in seeing different possible approaches to the same problem.