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

Hello Monks,

I have this bis of code for printing into a file:
open OUT, ">".$self->get_csv() || die "Could not open file ".$self->get_csv(). " for writing!"; for ( my $i = 0; $i < @stations; $i++ ){ print OUT [some string]; } close OUT;
Every time I call this code I get a message, that I tried to print on a closed filehandle called OUT, yet the "die" command is not called. I am a lost what else could call this error. Any help is appreciated.
I am not sure if this might be a Windows specific problem but in case it is: (WinXP, Active Perl 5.8.4/810)

Thanks.

Replies are listed 'Best First'.
Re: Print on closed filehandle
by Fletch (Bishop) on Jul 15, 2004 at 13:17 UTC

    You have a precedence problem. Use or, not ||. See perldoc perlopentut.

Re: Print on closed filehandle
by dave_the_m (Monsignor) on Jul 15, 2004 at 13:18 UTC
    open OUT, ">".$self->get_csv() || die "Could not open file ".$self->get_csv(). " for writing!";
    Change the '||' to an 'or'. The latter version has low precedence.

    Dave.

      Oops, well that works fine, thank you.
A reply falls below the community's threshold of quality. You may see it by logging in.