Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old December 11th, 2000, 10:25 AM
kaptiv kaptiv is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2000
Posts: 1 kaptiv User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I need to check for the existence of a specific string at the beginning of a variable and based upone its existence/absence perform a conditional branch. The line I am attepting to use is as follows -

if ($zip =~ /^191*/)

testing for the characters 191 at the beginning of the $zip variable. Is this code correct or am I having a major brain fart here? Any feedback is mucho appreciated.

K

Reply With Quote
  #2  
Old December 13th, 2000, 11:46 AM
luciddream luciddream is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Location: Ft. Lauderdale, FL, US
Posts: 29 luciddream User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
this code is correct, kinda...

if you are testing for the character * you need to escape it by doing * .

but if you are using it to say zero or more characters after the 191, then you can either use .* or nothing... it should work the same.



Reply With Quote
  #3  
Old December 16th, 2000, 05:06 PM
Anonym0us Anonym0us is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Posts: 0 Anonym0us User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
All you have to do is:
if ($zip =~ /^191/) {
# true
} else {
# false
}

[Update] I also just realized that your pattern is wrong because all numbers starting with "19" would be flagged as OK. Try my solution above.

[This message has been edited by Anonym0us (edited December 16, 2000).]

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Help - String manipulation/Conditons


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway