Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Problems with open $FH

by walto (Pilgrim)
on Apr 25, 2008 at 04:21 UTC ( #682752=perlquestion: print w/replies, xml ) Need Help??

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

Hello Monks,
I want read/write access to a file. I run this script on Vista with ActiveState Perl-5.10.0.
use warnings; use strict; open my $FH,">>","test.txt" or die ">>: $!"; my @file = <$FH>; if (defined $file[0]){ print "Open with >>: ",shift @file,"\n"; } else { print "Open with >>: undef\n"; } close $FH; open my $IN,"+<","test.txt" or die "#<: $!n"; my @file_new = <$IN>; if (defined $file_new[0]){ print "Open with +<: ",shift @file_new,"\n"; } else { print "Open with +<: undef\n"; } close $IN;

I get this output:
Open with >>: undef Open with +<: Test

Until this "problem" occured I opened the files I had to access (read/write) with ">>" and it worked as I expected.
Is this something related with Perl 5.10?

Replies are listed 'Best First'.
Re: Problems with open $FH
by jwkrahn (Monsignor) on Apr 25, 2008 at 05:11 UTC
    I opened the files I had to access (read/write) with ">>" and it worked as I expected.

     ">>" mode is not read/write.   From perlopentut:

    To open a file for appending, creating one if necessary: open(FH, ">> $path"); sysopen(FH, $path, O_WRONLY | O_APPEND | O_CREAT);

    Notice the O_WRONLY (write only) attribute.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2021-01-27 09:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?