http://www.perlmonks.org?node_id=932218


in reply to Is there a way to compare strings without using an array?

say $line2 =~ /[$line1]/g; say $line1 =~ /[^$line2]/g, $line2 =~ /[^$line1]/g;

Replies are listed 'Best First'.
Re^2: Is there a way to compare strings without using an array?
by CountZero (Bishop) on Oct 18, 2011 at 20:08 UTC
    With duplicates removed and the output sorted:
    use Modern::Perl; my $line1= 'CABGFEBFA'; my $line2= 'DBFDDF'; say sort keys %{{map {$_ => 1} $line2 =~ /[$line1]/g}}; say sort keys %{{map {$_ => 1} $line1 =~ /[^$line2]/g, $line2 =~ /[^$l +ine1]/g}};

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re^2: Is there a way to compare strings without using an array?
by Jeri (Scribe) on Oct 18, 2011 at 19:34 UTC
    say for $line1 =~ /[$line2]/g;

    it complains...

    Bareword "say" not allowed while "strict subs"

    when I delete say, it complains...

    syntax error at evan.pl line 8, near "$line1 =~"

    What's the trick to this sting comparison?

    thanks!
        thanks, it's working

        Why is it necessary to use 'say'? If I took out..

        use feature 'say';

        and the 'say' in...

         say for $line1 =~ /[$line2]/g;

        Why doesn't it work?