Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-13-2003, 02:29 PM   #1
Registered: Nov 2003
Location: Ontario, Canada
Distribution: Ubuntu
Posts: 269

Rep: Reputation: 30
Simple Perl Question

Is there a way to compare strings in Perl ignoring the case of the characters?

For example:

$str1 = "somestring";
$str2 = "SomeString";

if ($str1 eq $str2) {
print "Success!!";

I want "Success!!" to happen here, but the case of the strings would have to be ignored.

Sorry if this is a dumb question - I'm new to Perl!
Old 11-13-2003, 09:17 PM   #2
Registered: Aug 2003
Location: Planet Earth
Distribution: Linux Mint Debian Edition (LMDE)
Posts: 215

Rep: Reputation: 31
You can use case-insensitive regular expression pattern matching. If you're planning on doing much Perl programming you should buy "Programming Perl", which is the best reference book on the language. See the "Pattern Matching" section of that book.

if( $str1 =~ /$str2/i ) {
   print( "Success!!\n" );

Last edited by eric.r.turner; 11-14-2003 at 08:50 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
simple Perl Question whohasit Programming 3 11-05-2004 10:52 AM
simple Perl question true_atlantis Programming 5 11-18-2003 08:37 PM
Simple Perl question! Please help! jacksmash Programming 4 11-07-2003 05:56 AM
Simple Perl Question Programming 6 07-18-2002 09:46 AM
A simple perl programming question J_Szucs Programming 12 07-14-2002 10:03 PM

All times are GMT -5. The time now is 02:33 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration