in reply to Re^2: Error: Not enough space
in thread Error: Not enough space

I think the point has already been made. You aren't supposed to look in $! unless an error has just occured. For instance

print $fh "foo\n" or die "Error writing: $!";

Since we dont know where your $! testing code occurs, theres any number of possibilities as to how $! can be set. For all we know some part of your code catches an error at some point and leaves $! set. Consider the following program:

perl -le "print BLAH 'foo' or warn $!; print 'foo'; print $!";

The error message persists long after its relevent.

As and aside: please use <code> tags around any code you post. At the very least it will avoid errors like the one at the bottom of your post. ;-)

HTH

---
demerphq

Replies are listed 'Best First'.
Re^4: Error: Not enough space
by jhazra (Novice) on Jan 05, 2005 at 00:22 UTC
    thanks demerphq.
    With your point in mind, its very clear that some part of my code is throwing "Not enough space" error message. Now how is that possible as there is enough memory availbel. No matter which part of the program sets it, its MY program only which is setting it. So even if I check for $! value at the end of the program, and it has an error value that signifies that the program generated that error while running ( though at that point the error may be invalid or in other words the error may have been generated at the line 1 itself and I am catching it at end of the program). So the question why/how this error "Not enough space" is possible in a system having so much memory and resources. For example:
    @arr[some very high no which causes a memory exception] = 88; # at this point $! is set to "Not enough memory" #I do some work here print "Hello world"; print "Hello world"; print "Hello world"; # here I check $! and $! is "Not enough memory" which means that the p +rogram threw "Not enough memory" at some point in time during its exe +cution before this point. And it just happens that no other system ca +ll has generated any other error from the time "Not enough memory" wa +s thrown. If the pevious array allocation didnt throw any error then +$! here will be still unset or 0( thats what I expect, please correct + me if I am wrong). if ($!) { # error exit(0); } print "$arr[0]";

    Or is it that the value of $! can be "Not enough space" even without my program causing a memory exception? Meaning $! can be a dangling one? appreciate your thoughts. Jayanta

      You can't do a bunch of things and then check $! and have it be meaningful at all. Until you know exactly which statement caused $! to be set there is no point in looking at it at all. DBI, or any one of the modules you have in use may be setting $! inadverdantly and its value by the time you check it is actually meaningless. Put a or die "Error:$!"; everywhere it makes sense and see what happens, but drop the catchall test on $! at the end of your code, its worse than useless.

      ---
      demerphq

      its very clear that some part of my code is throwing "Not enough space" error message.
      Strictly speaking, you can't be sure, since errno is only defined to have a meaning immediately after an error. Not sometime later, or before an error occured.

      You might be right that your program does indeed cause an ENOMEM error, but since you don't check $! at the right place, you're never going to be sure if and why it does.

      You can fix this easily - system calls have a return code. Use it.

        Ok in that case, which ones are considered to be system calls? is it only the system(..) calls or it is any call to underlying c routines also? Like can a call to print FH "foo"; cause ENOMEM? or can an array allocation cause an ENOMEM? so which all statements in the code should be checked for $! ? Here's an example:
        @arr = ('x', 'y', 'z'); # error occurs so $! is set. But thinking that this small piece of cod +e wont cause any error I dont check for $! here. #some more code her print join(',', @arr); open(FILE, "<file.txt") || die (".....error"); # check for $! here if ($!) { # whcih is the culprit line causing this error? is it array allocation +, or is it print or is it open? }
      Or is it that the value of $! can be "Not enough space" even without my program causing a memory exception?

      Yes. Check to see if the print right before the # here I check $! returned true or false. If it returned false, that print got an error ("Not enough space."). If it returned true, $! is meaningless. Which is to say an error may or may not have occured earlier, but you have no way of knowing. This is stated in the documentation for $! in perlvar.

        Ok in that case, which ones are considered to be system calls? is it only the system(..) calls or it is any call to underlying c routines also? Like can a call to print FH "foo"; cause ENOMEM? or can an array allocation cause an ENOMEM? so which all statements in the code should be checked for $! ? Here's an example:
        @arr = ('x', 'y', 'z'); # error occurs so $! is set. But thinking that this small piece of cod +e wont cause any error I dont check for $! here. #some more code her print join(',', @arr); open(FILE, "<file.txt") || die (".....error"); # check for $! here if ($!) { # whcih is the culprit line causing this error? is it array allocation +, or is it print or is it open? }