Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Is there a way to compare strings without using an array?

by Anonymous Monk
on Oct 18, 2011 at 19:01 UTC ( #932218=note: print w/ replies, xml ) Need Help??


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;


Comment on Re: Is there a way to compare strings without using an array?
Download Code
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?

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://932218]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2014-07-24 05:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (158 votes), past polls