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

Re: File open head scratcher UPDATE

Thread Previous
From:
Doran, Michael D
Date:
March 17, 2012 16:43
Subject:
Re: File open head scratcher UPDATE
Message ID:
E2CC6171-E8D3-4D33-B171-C4DA3DD0C2A2@uta.edu
Hi Brad,

This is interesting.  Thanks for delving deeper into this.

I'd prefer that my high level scripting language didn't make me think about this type of thing... but I guess that's not being realistic.  ;-)

-- Michael

Sent from my iPad

On Mar 17, 2012, at 6:17 PM, "Brad Baxter" <bmb@mail.libs.uga.edu> wrote:

> 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


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