#!/usr/bin/perl use strict; use warnings; ### Standard Getopt::Long / Pod::Usage header ### use Getopt::Long; use Pod::Usage; my $DEBUG=0; my %options = (); my @config = qw/help|? man glob=s dir=s pipe=s command=s@ file=s/; GetOptions( \%options, @config ) or pod2usage(2); pod2usage(1) if exists $options{'help'} || not keys %options; pod2usage( exitstatus => 0, verbose => 2 ) if exists $options{'man'}; # # Author: Murat Uenalan (muenalan@cpan.org) # our $VERSION = '0.03'; # Main code $options{command} = ['ls -la'] unless exists $options{command}; if( exists $options{file} ) { open( FILE, $options{file} ); @ARGV = ; chomp @ARGV; close( FILE ); } if( exists $options{'glob'} ) { chdir $options{'dir'} if exists $options{'dir'}; @ARGV = glob $options{'glob'}; } elsif( exists $options{'pipe'} ) { @ARGV = qx{$options{'pipe'}}; chomp @ARGV; } foreach my $command ( @{ $options{command} } ) { print qx{$command \"$_\"} for @ARGV; # unless $command =~ /VAR/; } __END__ =head1 NAME perdo - command for mass work =head1 SYNOPSIS perdo [options] [file ...] Options: -help brief help message -man full documentation -command=s@ a list of commands -file path to a textfile with filenames -glob glob shell expression -pipe execute a command and use result as filename list (ie. find) -dir define other than current dir (for globbing) =head1 OPTIONS =over 8 =item B<-help> Print a brief help message and exits. =item B<-man> Prints the manual page and exits. =item B<-command> a list of shell commands (default: "ls -la") =item B<-file> on every line in this file =item B<-pipe> the result of this command(s) will be used as the item list =item B<-glob> on every item from this glob =item B<-dir> define other than current dir (for globbing only) =back =head1 DESCRIPTION B will read the given input file(s) and do something useful with the contents thereof. =head1 Example - 'ls -la' on all perlscript files in the perlbin directory perdo -g *.pod -d perlbin - print all pod documentation (in the perlbin directory) perdo -c perldoc -g *.pod -d perlbin - cat all perlscript perdo -c cat -g *.pl - gunzip all .gz files perdo -c gunzip -g *.gz - untar all tarfiles and then remove the archives perdo -c "tar xvf" -c "rm" -g *.tar ! warning: vice versa in the commands order would be fatal ! - grep recursivly in all files for a string perdo -pipe "find -not -type d" -command "grep -i muenalan" =cut