Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

How to match String with Case Sensitive??

by Sachin (Acolyte)
on Oct 30, 2009 at 11:29 UTC ( #804132=perlquestion: print w/ replies, xml ) Need Help??
Sachin has asked for the wisdom of the Perl Monks concerning the following question:

Anybody can tell me any method to match Case Sensitive String. I wouldnot like to convert the $test1 in lowercase. I want to match as it is.

#! /usr/bin/perl my $test = "abc"; my $test1 = "AbC"; if($test =~ m#$test1#i){ print "\n Both are Same"; } else{ print "\n Both are not Same"; }

Comment on How to match String with Case Sensitive??
Download Code
Re: How to match String with Case Sensitive??
by moritz (Cardinal) on Oct 30, 2009 at 11:46 UTC

    If you want case sensitive matching, just remove the i at the end.

    In any case your test will return true if $test1 is a substring of $test, and if it contains special regex syntax it's something else completely. So you could do

    if ($test =~ m/^\Q$test1\E\z/) { ... }
    instead to avoid that.
    Perl 6 - links to (nearly) everything that is Perl 6.

      Thansk for Reply. I removed the i at the end. But it is not matching.

      #! /usr/bin/perl my $test = "abc"; my $test1 = <STDIN>; # Suppose test1 = "AbC" if($test =~ m#$test1#){ print "\n Both are Same"; } else{ print "\n Both are not Same"; }
        That's because the line terminator, "\n" is at the end of $test1.
        chomp($test1);

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2014-09-20 12:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (159 votes), past polls