Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Problems with open $FH

by walto (Pilgrim)
on Apr 25, 2008 at 04:21 UTC ( [id://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 (Abbot) 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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (1)
As of 2026-01-18 06:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (121 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.