aboutsummaryrefslogtreecommitdiffstats
path: root/tools/replace_version.pl
blob: 845948d81e6d54b188d0ecab4db85a769b9bfe41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/perl

####
# Usage
#
# perl replace_version.pl --file=/path/to/file.php --version=2.8.0

use strict;
use warnings;

use Getopt::Long;
use File::Basename;

my %opt = ();
GetOptions(
    \%opt,
    qw/
          file=s
          version=s
      /
);

if (not -e $opt{file}) {
    die "file missing ".$opt{file};
}

my $new_content = '';
open(my $ifh, '<'.$opt{file}) or die 'Houston, problem with "'.$opt{file}.'" for reading';
while (<$ifh>) {
    if (/^Version:/) {
        $_ = 'Version: '.$opt{version}.''."\n";
    }
    $new_content.= $_;
}
close($ifh);

open(my $ofh, '>'.$opt{file}) or die 'Houston, problem with "'.$opt{file}.'" for writing';
print {$ofh} $new_content;
close($ofh);