LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 02: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, 09:17 PM   #2
eric.r.turner
Member
 
Registered: Aug 2003
Location: Planet Earth
Distribution: Linux Mint
Posts: 216

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 08:50 AM.
 
  


Reply



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 Danny.au Programming 6 07-18-2002 09:46 AM
A simple perl programming question J_Szucs Programming 12 07-14-2002 10:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:17 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration