Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Failed to close file

by ovedpo15 (Monk)
on Aug 24, 2019 at 09:58 UTC ( #11104937=perlquestion: print w/replies, xml ) Need Help??

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

Hello monks!,
I have the following code:
open(PACK,">$pack") or die("failed to open file $pack"); print PACK <<_M_E; #!/usr/intel/bin/tcsh -f $sanity_code $tests _M_E close(PACK) or die("failed to close file $pack");
Always when I run my tests I get:
failed to close file <path> at <script> line 400.
The strange thing is that I never get it for opening, just for closing.
What could bring to this behavior? how to solve it?
Edit:
Thank you all for the comments. I added the $! and it prints "Disk quota exceeded". But it looks like I have available space.
I run `df /path/to/the/file/which/we/try/to/open` and I have 57% free space. What could be the issue?

Replies are listed 'Best First'.
Re: Failed to close file
by haukex (Chancellor) on Aug 24, 2019 at 10:04 UTC
Re: Failed to clode file
by marto (Archbishop) on Aug 24, 2019 at 10:08 UTC

    Use three argument open, let perl tell you why this failed, $!.

Re: Failed to close file -- tests
by Discipulus (Abbot) on Aug 24, 2019 at 12:11 UTC
    Hello ovedpo15,

    > Always when I run my tests I get:

    probably something related with tests path? Is $pack a full path or a relative one? Is a temp dir?

    Depending on the OS there are method to see who is maintaining the file open. I suppose you are on linux.. If not inspect also $^E to see last system error.

    Your open is better written (as already pointed) in the 3 form; this as the avantage to have the path at disposition when printing errors.

    You can also try to see if fileno returns something. Avoid also unnecessary parentheses

    my $full_path = '/path/to/file'; #open my $fh, '>', $full_path or die "Unable to open [$full_path] to w +rite!"; # see tinita below.. open my $fh, '>', $full_path or die "Unable to open [$full_path] to wr +ite! $!"; ... # this one or some variation.. close $fh or warning "unable to close [$full_path] $! fileno: ".(filen +o $fh)." -e ".(-e $full_path); # more checks on directory? die if fileno $fh;

    PS you have a typo in the title: correct it for future seekers

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
      The error message for open should also include $!
Re: Failed to close file
by Marshall (Abbot) on Aug 24, 2019 at 16:32 UTC
    Your code works on my machine when the variables $sanity_code and $tests are simple short strings.

    I suspect that the problem is that further up in the code wherever those variables are calculated, there is some humongous result. Try just printing $sanity_code and/or $tests to STDOUT instead of to PACK and see what happens....

    #!/usr/bin/perl use strict; use warnings; my $pack = 'test.txt'; #fine when using these vars.... my $sanity_code = "blah"; my $tests = "asdfasdf"; open(PACK,">$pack") or die("failed to open file $pack"); print PACK <<_M_E; #!/usr/intel/bin/tcsh -f $sanity_code $tests _M_E close(PACK) or die("failed to close file $pack");
Re: Failed to clode file
by karlgoethebier (Monsignor) on Aug 24, 2019 at 11:27 UTC

    You may try autodie. (Did someone notice that i‘m a poet?) Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Re: Failed to clode file
by Anonymous Monk on Aug 24, 2019 at 10:06 UTC
    Try printing $! in your error message and see what it says. Also check for errors in print (and make sure to print $! in that case, too).
Re: Failed to clode file
by ovedpo15 (Monk) on Aug 24, 2019 at 11:58 UTC
    Thank you all for the comments. I added the $! and it prints "Disk quota exceeded". But it looks like I have available space.
    I run `df /path/to/the/file/which/we/try/to/open` and I have 57% free space. What could be the issue?

      The message "Disk quota exceeded" is explicit - it means that your user's (or group's) disk quota has been exceeded, not that there is no space left on the device. See eg. repquota for more detail.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11104937]
Approved by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2019-09-23 11:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (279 votes). Check out past polls.

    Notices?