in reply to [SOLVED]open to read file, erases all my files

The error is in your program. Most likely, you overwrite your files because not only do you open them for reading but also open them for writing somewhere.

As you don't show any working code, it's hard to help you further. I would replace the opening and writing of files by subroutines that simply print what they do instead of doing. This should show you that you are trying to write to the files that you are supposed to read.

Of course, this is some basic debugging strategy - suspecting a bug in Perl is a bad approach if you haven't done any debugging yourself.

Replies are listed 'Best First'.
Re^2: stdin erases all my files
by baxy77bax (Deacon) on Jul 02, 2010 at 12:16 UTC
    ok, but then why doesn't it erase my files when i change the path to './', then it behaves normally. but if i switch the path to './somewhere/' it erases the whole ./somewhere/ folder. the folder still exists but it is empty. and i cannot find the bug in my code. plus it does this for every function , procedure.(and only common things for all functions are , stdin, Term::ReadLine and eval()) i would expect that if i had a bug then other functions should not work properly but the behavior is universal. so it led me to a conclusion either something is happening during eval() operation or stdin doesn't work properly with Term::ReadLine so ....

    but thnx :)

    PS

    even if in the folder are files that are totally unrelated with my work, they are also erased. folder gets completely erased it is like i called :rm -r ./dir/ and then mkdir ./dir/ even the existing dir's in that dir get erased...

    agreed, it's gonna take me a while but i try to do it and post it

      How am I supposed to tell from your vague description?

      You need to note that your vague description is necessarily vague because if you could describe your code exactly, you would also know where the problem is. So you will need to show us the code, or at least the reduced code that still exhibits the problem but is shorter than 20 lines.

      Usually this kinds of problems turns to be something else that we haven't considered, and probably you already believe that is something wrong with the open ( which might be or not ) and you focus only on that.

      Try to write a shorter program that only opens a directory and see if that removes everything, ... or run your program using the debugger with perl -d your_program.pl and check if after each step the directory gets wiped out, if so you'd find the line that did it and you'd be available to write a minimal program that evidences the bug ( or new test case for perl 5.12.X :D )