Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2004
    Posts
    6

    Unanswered: Perl Script question

    I have a question regarding a SQL statement that I have in my perl program.

    I am using the following code:
    # SQL scalar
    my ($SQL);

    # Scalars for database columns
    my ($userid, $username, $useremail, $userpwd, $useroffice);

    # Initialise the values for an example request
    $userid = "5";
    $username = "alice";
    $useremail = "alice@yahoo.com";
    $userpwd = "blah2000";
    $useroffice = "san antonio";


    $SQL = "INSERT INTO users (userid, username, useremail, userpwd, useroffice) VALUES ('$userid', '$username', '$useremail', '$userpwd', '$useroffice')";

    # Run the SQL query
    if ($db->Sql($SQL))
    {
    print "Error on SQL INSERT\n";
    Win32::ODBC:umpError();

    } # End if

    print "<p>Running: $SQL<br>\n";
    print "Note: $username has been created\n";


    if you notice the useremail section includes a '@' character. This is not going to display the result that I want. How do I get perl to print the full email address correctly.

    Right now, the result looks like this:

    5 alice alice.com blah2000 san antonio

    but I want it to display alice@yahoo.com

    Any suggestions?
    Thank You.
    -Laura

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Because the at sign (@) is the preface character for a Perl array, you can't use it directly within a string constant. If you read an at sign from a file or accept it from a user it works just fine, but to use it as a constant you must escape it's special meaning. So you'd use "alice\@yahoo.com" instead of just "alice@yahoo.com" to get the literal at sign into the string.

    -PatP

  3. #3
    Join Date
    Apr 2004
    Posts
    6

    Talking

    Ohhh. I forgot about that. I am learning perl still.
    Thanks for being patient with me.
    -Laura

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    No problem. Compared to most other scripting languages, Perl is monsterously expressive. If a batch file is a blow gun, Perl is more comparable to an M1 Abrams. It takes a bit longer to learn to use Perl, but the effort pays for itself many thousand times over!

    -PatP

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •