in reply to Tie::File is sucking the life out of me

The road to perdition is paved with good intentions. ...I used to think that was true until I saw someone tie a file, and then open the same file for input before ever untieing it.

Seriously though, that's a shady thing to be doing, don't you think? You're exposing your script to the nuances of buffering. Nevertheless, your script isn't doing any writing, so buffering seems to not be at play here.

However, when I ran your script, I got the following message:

Can't locate object method "TIEARRAY" via package "Tie::File" at C:\Pe +rl\scripts\mytest.pl line 11.

...That's the error I got, until I remembered that you can't very well use Tie::Array without first having a line near the top of the script that says, "use Tie::Array;". Oops. Putting that line where it belongs in your script was all it took for it to "work".

Your riddle was made just a little more difficult to solve because you chose to tell us "I've got one machine where the script works, and one where it doesn't.", instead of helping us out by telling us what error and/or results you got. That would have been helpful information. Since I have to guess that your results were similar to mine, I have to wonder if the real riddle isn't how you got the script to work on the other machines without the important line, "use Tie::File;"

Update:

However, if by chance that isn't your problem, I would also look into the possibility of failing to convert your line endings when moving the script from a Windows environment to a Unix/Linux environment. That can cause a failure as well. Post your error message and we'll have a better idea of what's actually at play here. ...or don't post it and just keep us guessing. ;)


Dave

Replies are listed 'Best First'.
Re: Re: Tie::File is sucking the life out of me
by GaijinPunch (Pilgrim) on Apr 27, 2004 at 07:09 UTC
    Sorry I didn't give enough info

    0) use Tie::File;
    Yes, it was in there from the begining. I didn't copy everything directly from the terminal, mainly b/c the data was sensitive. Sorry for the confusion. I figured since I mentioned I run the exact script flawlessly on other computers, that would be a given.

    1) I only opened up the file with a filehandle for testing - to make sure the file was alive, readable, and all that jazz. The original script tied the file, and that's all. (the only filehandle was to write output)

    2) Both machines are running version 0.93

    3) There's no error. It runs through the script, but seeing as how my array I've tied the file to has -1 elements, it's not really going to do anything... nothing good anyway.

    I guess that falls under the "keep you guessing" category.
      0) That makes a big difference, and is one possibility I suspected all along. Can you verify that the script you posted replicates the errant behavior? Because for me it doesn't. Since you're not showing us the actual code, it is encumbant on you to provide code that replicates the problem without introducing other bugs (ie, wild goose chases).

      1) Fine, but again we didn't know that. The fact is that your double-use of the same file isn't causing a problem in this case, it's just asking for trouble if you use it in production though. And we had no way of knowing that your test code introduced elements not present in your production code.

      2) Are both machines the same OS? If not, did you make sure to convert your line endings? I'm still keeping that one open as an option.

      3) I ran your script using a text file instead of an empty file. I also ran it with an empty file as you're doing. It worked fine both ways. So again I have to ask if this snippet you've provided replicates the errant behavior.

      As I said before, if you're dealing with different operating systems, ensure that you have converted your line endings.

      And jeffa may also be right, with the suggestion to ensure that on both of your machines, your script has permission to work with the file in question.


      Dave

        Okay, I figured it out. It was the permissions, even though anyone could read the file when I ran 'ls -ltr'.

        Is there something different about reading a file via file handle, as opposed to Tie::File? This is why I tried it the conventional way -- to see if I had permission to read the file.

        Anyways, thanks for the help.