--- nfo/perl/scripts/archiver/bin/modifier.pl 2003/02/01 02:56:03 1.1 +++ nfo/perl/scripts/archiver/bin/modifier.pl 2003/02/01 06:44:08 1.2 @@ -1,9 +1,12 @@ #!/usr/bin/perl ## ------------------------------------------------------------------------ -## $Id: modifier.pl,v 1.1 2003/02/01 02:56:03 joko Exp $ +## $Id: modifier.pl,v 1.2 2003/02/01 06:44:08 joko Exp $ ## ------------------------------------------------------------------------ ## $Log: modifier.pl,v $ +## Revision 1.2 2003/02/01 06:44:08 joko +## + added option and implementation for '--in-type=pathlist' +## ## Revision 1.1 2003/02/01 02:56:03 joko ## + initial commit ## @@ -36,6 +39,9 @@ use Data::Dumper; use Getopt::Easy; +#use Data::Storage::Handler::File qw( s2f ); +use Data::Storage::Handler::File; + # ---------------------------------------- package main; @@ -46,7 +52,7 @@ my $defaults = { options => { - 'in-type' => 'content', + 'in-type' => 'stdin', #'in-type' => 'pathlist', #'regex' => '.*', }, @@ -74,7 +80,7 @@ sub replace { - if ($settings->{options}->{'in-type'} eq 'content') { + if ($settings->{options}->{'in-type'} eq 'stdin') { my @buffer; my $pattern = $settings->{options}->{regex}; while () { @@ -85,7 +91,54 @@ } } elsif ($settings->{options}->{'in-type'} eq 'pathlist') { - die("not implemented yet!"); + #die("not implemented yet!"); + my $pattern = $settings->{options}->{regex}; + while () { + chomp; + print "modifying $_: "; + my $file = Data::Storage::Handler::File->new( path => $_ ); + #print Dumper($file), "\n"; + #print Dumper($file->toString()), "\n"; + #exit; + #print "replacing...", "\n"; + + if ($file->matches($pattern)) { + print "MATCH - "; + + if (my $suffix_backup = $settings->{options}->{backup}) { + if ($suffix_backup eq '1') { $suffix_backup = 'bak'; } + #print "made backup of original-file"; + $file->backup( { suffix => $suffix_backup } ); + } + + if ($settings->{options}->{infile}) { + print "replaced infile"; + die("not yet implemented"); + + } elsif ($settings->{options}->{overwrite}) { + print "overwritten"; + $file->save(); + + } elsif (my $suffix = $settings->{options}->{suffix}) { + print "suffixed with $suffix"; + $file->addSuffix($suffix); + $file->save(); + + } else { + print "no action (e.g. --infile|--suffix=tmp) applied"; + } + #exit; + + } else { + print "NO match - not touched"; + } + #print; + print "\n"; + #print Dumper($content), "\n"; + + #print "writing ....", "\n"; + #exit; + } }