/[gentoo]/src/fortune-gentoo-dev/split.pl
Gentoo

Contents of /src/fortune-gentoo-dev/split.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download) (as text)
Sat Apr 28 22:43:14 2007 UTC (11 years, 3 months ago) by robbat2
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-perl
Initial commit of fortune-gentoo-dev upstream package.

1 #!/usr/bin/perl
2 # Copyright 1999-2007 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # $Header: $
5 #
6 # This script is designed to split an existing fortune file into it's component
7 # entries, one per file.
8 # Robin H. Johnson <robbat2@gentoo.org> (28 Apr 2007)
9 use strict;
10
11 my $ifhn = $ARGV[0];
12 open IFH,'<',$ifhn or die "Failed to open '$ifhn' - $!";
13 my $n = 0;
14 my $i = undef;
15 my $ofhn;
16
17 while(<IFH>) {
18 chomp;
19 if(/^%$/) {
20 next if ($i == 0);
21 $i = 0;
22 $ofhn = sprintf ("%s_%05d",$ifhn,$n);
23 open OFH, ">",$ofhn;
24 $n++;
25 next;
26 }
27 $i++;
28 printf OFH "%s\n",$_;
29 }
30 if($i == 0) {
31 close OFH;
32 unlink $ofhn if(-s $ofhn == 0);
33 }

  ViewVC Help
Powered by ViewVC 1.1.20