Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- #author: Todd Davies
- #use: Appends a comment to java, pl and txt files in a directory with my name!
- #warning: It's probably best not to use it on anything other than text based files!
- #
- use Switch;
- @files = <*>;
- foreach $filename (@files) {
- my $new_fn = $filename . '.new';
- open my $in, '<', $filename or die "Cannot open $filename for reading - $!";
- open my $out, '>', $new_fn or die "Cannot open $new_fn for writing - $!";
- my $ext = ($filename =~ m/([^.]+)$/)[0];
- switch ($ext) {
- case "txt" { print {$out} "--------------------------\nauthor: Todd Davies\n--------------------------\n"; }
- case "java" { print {$out} "/*\n *author: Todd Davies\n */\n"; }
- case "pl" { print {$out} "#\n#author: Todd Davies\n#\n"; }
- else { }
- }
- while (my $line = <$in>)
- {
- print {$out} $line;
- }
- close($out);
- close($in);
- rename($new_fn, $filename);
- print "Processed: ".$filename."\n";
- }
- <>;
Advertisement
Add Comment
Please, Sign In to add comment