develooper Front page | perl.perl4lib | Postings from March 2012

Re: File open head scratcher

Thread Previous | Thread Next
From:
Dan Scott
Date:
March 17, 2012 14:18
Subject:
Re: File open head scratcher
Message ID:
CAAY5AM2zaRuhXdXPdB3ZSd071uJEsMXmCQfcRAX-NQ8sfR1eMQ@mail.gmail.com
On Sat, Mar 17, 2012 at 3:09 PM, Doran, Michael D <doran@uta.edu> wrote:
> I am migrating  a perl script from a server running perl v5.8.5 on Solaris 9 to a server running perl v5.12.2 on Redhat Linux 5.5.  The new environment doesn't seem to like the syntax I'm using to open a file, and I'm scratching my head over why that is the case.
>
> That part that is not working appears to be where it opens and reads a file (a file which it will later append to).  The file that is being opened for read and appending exists and contains data.
>
> This appears to be the relevant code:
>
>  open (my $DATEFILE, "+>>$date_file")
>        || die "Cannot open $date_file: $!";

The head-scratching behaviour you describe, where only the system call
outputs results, matches mine with perl 5.14.2. Maybe there's a
difference in the versions of perl on your two systems?

For what it's worth, "Mixing reads and writes" in perlopentut says
that you probably want:

open (my $DATEFILE, "+<", $date_file) ...

(and making that change to my copy of your script makes it work for me).

-- 
Dan Scott
Laurentian University

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About