adriang has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
I want to create a counter using a file but this don't work
#!/usr/bin/perl use warnings; use strict; use Carp; open(my $count_file,"+<","count.txt") or croak "cant open"; my $count=<$count_file>; $count++; print $count_file $count; print $count; __END__
only this work:
#!/usr/bin/perl use warnings; use strict; use Carp; open(my $count_file,"<","count.txt") or croak "cant open"; my $count=<$count_file>; $count++; open($count_file,">","count.txt") or croak "cant open"; print $count_file $count; print $count; __END__
I want to use OPEN only once.
Thanks in advace, Adrian.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File reade and recreate
by GrandFather (Saint) on Aug 20, 2014 at 07:58 UTC | |
by adriang (Sexton) on Aug 20, 2014 at 10:18 UTC | |
|
Re: File reade and recreate
by MidLifeXis (Monsignor) on Aug 20, 2014 at 13:42 UTC | |
by adriang (Sexton) on Aug 21, 2014 at 07:53 UTC |