schulerlab has asked for the wisdom of the Perl Monks concerning the following question:

during a recent upgrade, I kept getting the error "Inappropriate ioctl" when I would try to access a file that worked previously before the upgrade.

eventually, with a friend's help, we realized the problem was that the previous program used a different database method (because of a mod that I put in when the server that the site was on previously didn't have the default database method).

fine.. I deleted the old file, and let the upgraded program rebuild it.

However, my friend was trying different things related to this and another problem he had, and discovered that the TIE works differently depending on whether you use parentheses or not (and this is how he explained what he saw):

This is hard to explain. I'll try. This is what i observed:

When the script cannot open the existing database file (here, the file named 'messagelist',) for some reason it seems that the "tie() or Error" this is the same thing as: "tie() or die" section evaluates to a non-fatal termination and so the $! in Error sub returns a "blank":

/home/mysite/public_html/tarty/bbs/tigerT/messagelist :

Then, the messagelist somehow gets deleted (most likely by the Rebuild_Database sub.) So, when i refresh the screen to make a 2nd attempt of rebuilding the index, the $! in Error sub returns a "No such file or directory" error:

/home/mysite/public_html/tarty/bbs/tigerT/messagelist : No such file or directory

Now, i change the code and remove the parentheses from the tie command. That is, i change it from "tie() or die" to "tie or die". I then change the script to use another DBM file than DB_File (or the vice versa) and do a rebuild.

The script still cannot read the existing database file. But the "tie or die" section does Not evaluate to a termination. The script moves on to rebuild the database using the new DBM file and then replaces the old database file with the new one.

In most cases, the presence or absence of parentheses in a command doesn't make any differences. But in this case, it means a lot.

I only know this is the way it works but don't know why it works this way

why does the TIE work this way, and is there a writeup on the difference? We couldn't find any documentation on this.

thanks.
  • Comment on difference between tie with and without parentheses

Replies are listed 'Best First'.
Re: difference between tie with and without parentheses
by BrowserUk (Patriarch) on Jul 30, 2008 at 03:40 UTC
Re: difference between tie with and without parentheses
by ikegami (Patriarch) on Jul 30, 2008 at 00:34 UTC

    tie doesn't know whether parens where used or not.
    tie doesn't set $! meaningfully.

Re: difference between tie with and without parentheses
by AltBlue (Chaplain) on Jul 30, 2008 at 02:58 UTC

    Yet another XY Problem ;-/

    Rather than copy-pasting some sloppy details, you could have created some basic test case in order to demonstrate your claim. In the process, you / your friend could have "discovered" that there was no tie related problem whatsoever.

    Without any code to review, there's not much that I can add to what ikegami already said, but I'm under the impression that your friend forgot one more thing, tie's return value:

    tie VARIABLE,CLASSNAME,LIST
    This function binds a variable to a package class that will provide the implementation for the variable. VARIABLE is the name of the variable to be enchanted. CLASSNAME is the name of a class implementing objects of correct type. Any additional arguments are passed to the "new" method of the class (meaning "TIESCALAR", "TIEHANDLE", "TIEARRAY", or "TIEHASH"). Typically these are arguments such as might be passed to the "dbm_open()" function of C. The object returned by the "new" method is also returned by the "tie" function, which would be useful if you want to access other methods in CLASSNAME.