Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2003
    Location
    Chennai
    Posts
    11

    Unanswered: problem with tie function

    I am new to Perl programming. I have a statement like this
    tie %reservation, "DB_File", "reservations" or die "live live live... $!\n";

    When i run the cgi script i am not getting expected output. I looked into the apache's error log file. It shows "live live live" for the latest access. What is the problem here? Please help me.

    Thanks in advance,
    Navanee

  2. #2
    Join Date
    Apr 2004
    Location
    Chennai
    Posts
    1

    answer

    i give u example code try that style.use the syntax correctly.


    unlink "example";
    tie %h,"DB_File","example",O_RDWR|O_CREAT, 0640, $DB_HASH ||print ("not able to open");


    here example is the file(table) i open.first i erase existing data(optional).then i open it for read and write ,if it exists.otherwise, the table is created.u can also add no overwrite etc..i use the hash method.


    try this syntax.if any problem, plz inform me the error message.regards

  3. #3
    Join Date
    Apr 2004
    Posts
    16
    Code:
    tie %h,"DB_File","example",O_RDWR|O_CREAT, 0640, $DB_HASH ||print ("not able to open");
    This is a common mistake. This function will never give you a meaningful error message for two reasons.
    1) You do not include $! in your error message. I understand that its just creation so this doesn't matter much. See point two.
    2) Precedence rules make the || apply to the $DB_HASH, not the statement as a whole. Thus if the value of $DB_HASH is false, then it will die. If its not, it will never die even if the tie call fails. Instead you must use the "or" operator (it has lower precedence than ||) or you must use ( ) around the parameters in the function call.

    Code:
    tie %h,"DB_File","example",O_RDWR|O_CREAT, 0640, $DB_HASH or print ("not able to open: '$!'");
    That said, since you did these two things in your other code, what error message did the apache log show you? My guess is that there is more to the error message than the "live live live". Mostly the value of $! is what you want. If you notice how I put the $! in single quotes, it is just so that you can make sure you are seeing the entire message even if it contains funny characters or newline characters etc.
    perl -le 'print reverse reverse "just another perl hacker"'
    wush.net subversion hosting - remote hosted revision control with easy admin, ssl security & backups

Posting Permissions

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