Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Re: comparing strings

by Anonymous Monk
on Oct 30, 2002 at 16:26 UTC ( [id://209130]=note: print w/replies, xml ) Need Help??


in reply to Re: comparing strings
in thread comparing strings

Thanks blokhead, But I am still having a few problems... I incorporated the snippet you gave me which works fine apart from it doesn't print the correct no. of *'s to correspond to the number of mismatches! This is what i did its slightly different from yours.
for ($dna_counter = 0; $dna_counter < $length_dna ; $dna_counter++ ) { if (substr(@lines, $_, 1) eq substr (@lines2, $_, 1)) { print ''; } else { print "*"; } } print "\n";

Replies are listed 'Best First'.
Re: Re: Re: comparing strings
by petral (Curate) on Oct 30, 2002 at 17:52 UTC
    Of course, if you're using arrays, you just need
    if ($lines{$_] eq $lines2[$_]) {
    The following will replace the non-matching chars in the string  $str1 with "*" (and leave the matching chars) by converting $str2 to a regex:
    $str2 =~ s/./(?:($&)|.)/g; print map{$_||'*'} $str1 =~ /$str2/


      p
Re: Re: Re: comparing strings
by graff (Chancellor) on Oct 31, 2002 at 04:47 UTC
    This is what i did its slightly different from yours.
    ... if (substr(@lines, $_, 1) eq substr (@lines2, $_, 1)) ...
    Well, that's actually way different from what Blockhead was doing -- he was using "substr()" on a scalar ($line); substr() is not supposed to be used on an array (@lines).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-26 03:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found