diff options
author | Nicholas Clark <nick@ccl4.org> | 2011-05-14 17:22:55 +0100 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2011-05-19 10:18:14 +0100 |
commit | 73437b648f94e4d46b3838d3721a6f9c2985ac2b (patch) | |
tree | 474891e182740f43b6d7c566b4d8d446c55d6db6 /regen/regen_lib.pl | |
parent | 29c22b52682692a630218342d1997c803a3b487b (diff) | |
download | perl-73437b648f94e4d46b3838d3721a6f9c2985ac2b.tar.gz |
Add an optional 'mode' argument to open_new(), to open for appending.
Use this in regen/uconfig_h.pl
Diffstat (limited to 'regen/regen_lib.pl')
-rw-r--r-- | regen/regen_lib.pl | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/regen/regen_lib.pl b/regen/regen_lib.pl index 951c23b431..c56f56435c 100644 --- a/regen/regen_lib.pl +++ b/regen/regen_lib.pl @@ -62,13 +62,19 @@ sub rename_if_different { # Open a new file. sub open_new { - my ($final_name) = @_; + my ($final_name, $mode) = @_; my $name = $final_name . '-new'; - if (-f $name) { - unlink $name or die "$name exists but can't unlink: $!"; - } my $fh = gensym; - open $fh, ">$name" or die "Can't create $name: $!"; + if (!defined $mode or $mode eq '>') { + if (-f $name) { + unlink $name or die "$name exists but can't unlink: $!"; + } + open $fh, ">$name" or die "Can't create $name: $!"; + } elsif ($mode eq '>>') { + open $fh, ">>$name" or die "Can't append to $name: $!"; + } else { + die "Unhandled open mode '$mode#"; + } *{$fh}->{name} = $name; *{$fh}->{final_name} = $final_name; *{$fh}->{lang} = ($final_name =~ /\.(?:c|h|tab|act)$/ ? 'C' : 'Perl'); |