#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    1
    Rep 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
  2. #2
  3. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Location
    Ft. Lauderdale, FL, US
    Posts
    29
    Rep 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.


  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Posts
    0
    Rep 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).]

IMN logo majestic logo threadwatch logo seochat tools logo