![]() | ![]() | ![]() |
| |||||||
| Forums | Register | Groups | Awards | Arcade | Pets | T-Bucks / T-Store | Invite Your Friends | Blogs | Mark Forums Read |
| Web Design Forums and discussions on webdesign |
Web Design | |||||||||
|
|
|
|
| |||||
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| Civilians | Perl script below runs a particular command on multiple files. I use this script when I've written a bunch of PHP pages that I need to upload to a server with no PHP support. I create the PHP pages using ".html" extensions and then run: folder.pl 'php {} >../{}' *.html Here is the script: ==================== folder.pl ==================== #!/usr/bin/perl use Getopt::Long qw(GetOptions); my $VERSION = '1.1'; my $opts; GetOptions ( "usage|help|h" => \$opts{'help'}, "version" => \$opts{'version'}, "verbose|v+" => \$opts{'verbose'} ); if ($opts{'version'}==1) { print "$VERSION\n"; } &errormessage if ($opts{'help'}==1); $cmd = shift @ARGV || &errormessage; $nfiles = 0; while ($_ = shift @ARGV) { $nfiles++; $c = $cmd; $c =~ s/\{\}/$_/g; print '$ ' . $c . "\n" if ($opts{'verbose'}==1); system($c); } if ($nfiles==0) { die "Must specify some files!\n" } else { print "$nfiles files processed.\n" if ($opts{'verbose'}==1); } sub errormessage { print "\n"; print "folder.pl - folds a command onto multiple files\n"; print "Version $VERSION (c) 2005 Toby Inkster\n"; print "License: http://www.gnu.org/copyleft/gpl.html\n\n"; print "USAGE: folder.pl [options] command file [file...]\n\n"; print " \"command\" is a command to run on each file. Use {} to refer to the\n"; print " filename (much like the \"find\" command). You may find it benificial\n"; print " to use \'single quotes\' around the command.\n\n"; print " Many UNIX shells provide similar built-in functionality, but folder.pl\n"; print " has an easier syntax.\n\n"; print "OPTIONS:\n"; print " --verbose -v Be verbose.\n"; print " --usage --help -h Display help message.\n"; print " --version Display version.\n\n"; print "EXAMPLES:\n"; print " folder.pl \'php {} >../{}.html\' *.php\n"; print " folder.pl \'mv {} {}l\' *.htm\n"; print "\n"; exit; } ================================================== = -- Toby A Inkster BSc (Hons) ARCS Contact Me ~ http://tobyinkster.co.uk/contact |
|
![]() |
| Bookmarks |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| IE script Error | =?Utf-8?B?QWNjZXNzTnViaWU=?= | Microsoft Applications | 2 | 12-01-2004 16:00 |
| script.js | Kurt Van Keymeulen | Microsoft Applications | 5 | 08-02-2004 10:30 |
| Which Script Are They Using? | http://links.i6networks.com | Web Design | 2 | 08-02-2004 09:30 |
| Need Help with PHP Script | mcp6453 | Web Design | 2 | 07-08-2004 07:29 |
| VB script | Antony | Microsoft Applications | 1 | 06-16-2004 07:46 |
![]() | ![]() | ![]() |