CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
how to make my script case sensitive

 



SherwinJohn
New User

Jul 12, 2005, 10:55 AM

Post #1 of 8 (5732 views)
how to make my script case sensitive Can't Post

hi ppl, i'm trying to run a win2 resource kit using perl's switch
statement
..i have several options, one of this is

if ($choice =~ /^0|pulist/i){
@pulist = `pulist -a`;
print "@pulist";
last SWITCH;

please help me how to make this "/i" to case sensitive
the output should be an atom starting with
option 0 only..everytime i click 01, 02, 03..and so on..
it still accepts it as 0, well in fact, it should restrict it, I want my script to match "0" only, is there any mistake with the use of "i" Angelic


KevinR
Veteran


Jul 12, 2005, 11:21 AM

Post #2 of 8 (5730 views)
Re: [SherwinJohn] how to make my script case sensitive [In reply to] Can't Post

just remove the "i" option and the regexp will be case sensitive. "i" means to ignore case: case in-sensitive.
-------------------------------------------------


SherwinJohn
New User

Jul 12, 2005, 12:16 PM

Post #3 of 8 (5729 views)
Re: i think there's a bug in my script.. can you guys [In reply to] Can't Post

i think there's a bug in my script.. can you guys
give me a hand on this

printDiagUtils();
}
sub runChoice($){
my ($choice) = @_;
print "\n";
SWITCH:{
if ($choice =~ /^0|pulist/){
@pulist = `pulist -a`;
print "@pulist";
last SWITCH;
}
if ($diagnostic =~ /^1|cycle/){
@cycle = `cycle -v -P0`;
print "@cycle";
last SWITCH;

i already removed the "i" case insensitive regex, it still
does'nt restrict 00's & 10, it should only accept 0 and 1,
0 for pulist -a command, and 1 for cycle -v -P0 command..
something wrong with this code?


KevinR
Veteran


Jul 12, 2005, 3:38 PM

Post #4 of 8 (5719 views)
Re: [SherwinJohn] i think there's a bug in my script.. can you guys [In reply to] Can't Post

maybe you need to use the end of string anchor "$" in your regexp:


Code
if ($choice =~ /^0|pulist$/) { 
...
}

-------------------------------------------------


davorg
Thaumaturge / Moderator

Jul 13, 2005, 2:53 AM

Post #5 of 8 (5717 views)
Re: [KevinR] i think there's a bug in my script.. can you guys [In reply to] Can't Post


In Reply To

Code
if ($choice =~ /^0|pulist$/) { 
...
}



That should probably be


Code
if ($choice =~ /^(0|pulist)$/) { 
...
}


--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


davorg
Thaumaturge / Moderator

Jul 13, 2005, 2:56 AM

Post #6 of 8 (5716 views)
Re: [SherwinJohn] i think there's a bug in my script.. can you guys [In reply to] Can't Post

If you're just matching fixed strings then you probably don't need regexes. Just comparing strings will be quicker (and less confusing).


Code
if ($choice == 0 or $choice eq 'pulist') { 
...
}


Just because Perl has regexes, it doesn't mean they're always the right answer :)

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


(This post was edited by davorg on Jul 13, 2005, 4:24 AM)


SherwinJohn
New User

Jul 13, 2005, 4:07 AM

Post #7 of 8 (5711 views)
Re: [davorg] i think there's a bug in my script.. can you guys [In reply to] Can't Post

by the way sir dave... "oe" stands for what?

thanks


davorg
Thaumaturge / Moderator

Jul 13, 2005, 4:15 AM

Post #8 of 8 (5710 views)
Re: [SherwinJohn] i think there's a bug in my script.. can you guys [In reply to] Can't Post

It stands for a typo :)

It should be "or". I'll correct it.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives