Front page | perl.perl4lib |
Postings from March 2012
Re: File open head scratcher UPDATE
Thread Previous
|
Thread Next
From:
Brad Baxter
Date:
March 17, 2012 16:18
Subject:
Re: File open head scratcher UPDATE
Message ID:
CANBtU9YJGMg+v+FxPwkhMVbhOqEH7tXAR4kWfS8quh-=nPmJxA@mail.gmail.com
On Sat, Mar 17, 2012 at 5:25 PM, Doran, Michael D <doran@uta.edu> wrote:
> It looks like the read pointer was going to the beginning of the file on Solaris, but the end of the file on Linux. I've edited the script to do separate opens for when I need to read the file and when I need to append to it. I'm running the script now to check for any unintended consequences.
>
> My take-away on this, is to avoid the use of "+>>" to open a file. In fact, in doing further research I saw that exact advice in the Perl Cookbook, and for just this reason.
>
> Thanks to Brad Baxter for (pardon the pun) pointing me in the right direction.
>
> -- Michael
FWIW, the Perl version seems to make a difference, too ...
>> cat qt
#!/usr/local/bin/perl
use strict;
use warnings;
system 'echo "This is a test" > test';
open my $fh, '+>>', "test" or die $!;
print '[',<$fh>,']';
close $fh;
>> ./qt
[This is a test
]
>> /usr/local/bin/perl -v
This is perl, v5.8.8 built for sun4-solaris
>> cat qt
#!/usr/local/bin/perl
use strict;
use warnings;
system 'echo "This is a test" > test';
open my $fh, '+>>', "test" or die $!;
print '[',<$fh>,']';
close $fh;
>> ./qt
[]
>> /usr/local/bin/perl -v
This is perl 5, version 12, subversion 1 (v5.12.1) built for sun4-solaris
Thread Previous
|
Thread Next