Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

perl problem

Options
  • 12-05-2008 10:48am
    #1
    Registered Users Posts: 26,579 ✭✭✭✭


    i have a array which elements contain strings like so...


    <USERID>~<USERNAME>~<ADDRESS>~<TELEPHONE>~<MOBILE>~<SALARY>~<PRSINO>~<DOB>

    what i have is a web form that asks a user to put in their <USERID> and if the <USERID> entered is contained in a line in this array, then i want to run some SQL query.

    my $userID = $page->param(userID);
    chomp $userID;
    
    
    print "enter userID:<br/>";
    print "<form action=\"user.cgi\" method=\"get\">
            userID: <input type=\"\text" name=\"adduserID\" id=\"adduserID\"/>
            <input type=\"submit\" />
            </form>";
    
    
    @info  # contains the lines delimited by ~
    
    # variables to be used to store the values of the delimited string
    my $userID;
    my $userName;
    my $address;
    my $telephone;
    my $mobile ; 
    my $salary;
    my $prsino;
    my $dob;
    
    
    foreach my $line (@info)
    {
        if( $line =~ /(.+)~(.+)~(.+)~(.+)~(.+)~(.+)~(.+)~(.+)/ )
        {
            $userID = $1;
            $username = $2;
            $address = $3;
            $telephone = $4;
            $mobile = $5;
            $salary = $6;
            $prsino = $7;
            $dob = $8;
        }
    
        #before i check to see if the ID's are equal i print them out to see if they are equal.
        print "adduserID: $adduserID // userID: $userID";
        
        #so down here i want to check each $userID from each line against the userID entered by the user from the form.
        if($adduserID eq $userID)
        {
            print "the user has been found";
        }
        else
        {
            print "user not found";
        }
    }
    
    when "print "adduserID: $adduserID // userID: $userID";" prints to the screen i'll get output like this.

    adduserID: ABCxx12345 userID: ABCxx54321
    adduserID: ABCxx12345 userID: ABCxx54322
    adduserID: ABCxx12345 userID: ABCxx54323
    adduserID: ABCxx12345 userID: ABCxx54324
    adduserID: ABCxx12345 userID: ABCxx54324
    adduserID: ABCxx12345 userID: ABCxx12345

    as you can see the ID's match on the last line so the message "the user has been found" should be printed, instead i get the else statement executed.

    the match will only occur if i input a number in the form that is the first match eg. i input ABCxx54321. in that case the print out looks like this:

    adduserID: ABCxx54321 userID: ABCxx54321

    how come this doesn't match on any line bar the first one?

    i changed the actual variables of my program just so the above is an example the above is not actually what my program is going to do.


Comments

  • Registered Users Posts: 26,579 ✭✭✭✭Creamy Goodness


    problem sorted, lol.

    turns out the userid from the array had a space at the start of the string.

    d'oh.

    leaving this open just in case someone else makes the same silly mistake i did.


Advertisement