Release new version 0.7.3
[grml-tips.git] / grml-tips-tags
1 #!/usr/bin/perl
2 # Filename:      grml-tips-tags
3 # Purpose:       Extract available patterns from grml-tips file
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>, (c) Alexander Wirt <formorer@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 ################################################################################
8
9 use strict;
10 use Getopt::Long;
11
12 my $grml_tips = '/usr/share/grml-tips/grml_tips';
13
14 my $result = GetOptions (
15         "tipsfile=s" => \$grml_tips
16 );
17
18 open (my $fh, '<', $grml_tips) or die "Could not open $grml_tips: $!";
19
20 my @tags;
21
22 while (my $line = <$fh>) {
23     next unless $line =~ /^Tags: (.*)$/;
24     push @tags, split(/[, ]+/, $1);
25 }
26
27 close ($fh);
28 #make tags unique
29 my %seen = ();
30 @tags = grep { ! $seen{$_} ++ } @tags;
31
32 open (my $fh, '>', '/usr/share/grml-tips/tags') 
33         or die "Could not open '/usr/share/grml-tips/tags' for writing: $!";
34 print $fh join("\n", @tags) . "\n";
35 close($fh)