in reply to Re^2: Error reading line from file: Operation timed out
in thread Error reading line from file: Operation timed out

You shouldn't make assumptions. I never said to go ahead and open the file even if it doesn't exist. If it doesn't exist, don't try to open it unless you are wanting to create it... I may not have been completely clear but there is some common sense involved here... "Checking -e after a failed open is prone to race conditions" says exactly what I'm saying. You also made the assumption that this file was in the "outside world" when that wasn't the case as per robertobouza's latest post. If the file is locally on his machine then just hammering it to see if it works is not the answer...


The Web is like a dominatrix. Everywhere I turn, I see little buttons ordering me to Submit. (Nytwind)
  • Comment on Re^3: Error reading line from file: Operation timed out

Replies are listed 'Best First'.
Re^4: Error reading line from file: Operation timed out
by moritz (Cardinal) on May 13, 2009 at 20:24 UTC

    I don't understand the points you're trying to make. To me the "outside world" is everything that the perl script doesn't control. That includes all files you're trying to open.

    If it doesn't exist, don't try to open it unless you are wanting to create it

    Uhm. Trying to open a file for reading (which is the default mode of open) does not create it under any circumstance.

    You also made the assumption that this file was in the "outside world" when that wasn't the case as per robertobouza's latest post

    Since robertobouza post was a reply to mine, how could I have known what he was going to reply to me?

    Even if it doesn't change in the mean time, there is absolutely no benefit in check its existence before trying to open it. Suppose you want to be thorough, then you'd have to write something like this:

    if (!-e $file) { die "'$file' does not exists'; } if (!-r $file) { die "insufficient permissions to read `$file'"; } if (-d $file) { die "`$file' is a directory, not a plain file"; } # and so on

    Actually there are error conditions (like out of memory) that you can't know in advance.

    Instead you just do open my $handle, '<', $file or die "Can't open `$fil'e for reading: $!"

    And even if the file doesn't change in this case, it can't hurt to stop with bad practices now.

    . If the file is locally on his machine then just hammering it to see if it works is not the answer...

    Why not? I see no reason not just to try it. I hope I illustrated the reasons for doing so (large number of checks necessary; some checks are impossible to do in advance; danger of race conditions)

      Thank you for the clarification. I see my errors now. Thanks for the discussion.

      The Web is like a dominatrix. Everywhere I turn, I see little buttons ordering me to Submit. (Nytwind)
Re^4: Error reading line from file: Operation timed out
by robertobouza (Initiate) on May 13, 2009 at 20:10 UTC
    Roy,

    Thanks for the Text::Template. Just changed a few logic on my classes and it works like a charm...

    I'm still a little bit intrigued of what I did and why didn't work... but for now I'll leave it on the side. I'll worry about it when this happens again.

    thanks again for your help.