LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 11-13-2003, 03:29 PM   #1
jacksmash
Member
 
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, 10:17 PM   #2
eric.r.turner
Member
 
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.

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

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


Reply


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 11:52 AM
simple Perl question true_atlantis Programming 5 11-18-2003 09:37 PM
Simple Perl question! Please help! jacksmash Programming 4 11-07-2003 06:56 AM
Simple Perl Question Danny.au Programming 6 07-18-2002 10:46 AM
A simple perl programming question J_Szucs Programming 12 07-14-2002 11:03 PM


All times are GMT -5. The time now is 05:28 AM.

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