At 04:12 PM 2/8/02 -0800, Scott Lutz wrote: >This should be a weekly thing : >See who can send in the most useful Perl one liner!
Hie thee to the Fun With Perl list (see lists.perl.org). This is not necessarily the stuff of beginners. >So to start it off, I would like some suggestions on some "not so >cryptic" one liner methods to do the following : One-liners and "not so cryptic" don't always go together, you realize... >#!/usr/bin/perl -w >use strict; > >opendir(TEMP_DIR, "/home/slutz/temp"); > my @items = grep(/\.BAD/,readdir(TEMP_DIR)); >closedir(TEMP_DIR); > >my ($file, $line); > >foreach $file (@items) { > print "Going into file : $file\n"; > open(FIN, $file) || warn "cant open the damn file : $!"; > while ( $line = <FIN> ){ > if ( $line =~ m'[EMAIL PROTECTED]' ) { > rename "/home/slutz/temp/$file", >"/home/slutz/temp/bad_email/$file" || die "$!"; > print "moved file /home/slutz/temp/$file to >/home/slutz/temp/bad_email/$file\n"; > } > } > close(FIN); >} > > >Thanks in advance! Okay, I'll play: cd /home/slutz/temp; perl -nle '(rename $ARGV, "bad_email/$ARGV" or die $!) and print "Moved $ARGV" and close ARGV if /looking_glass\@telus\.net/' *.BAD If you don't have to die on bad rename()s then you can just: perl -nle 'rename $ARGV, "bad_email/$ARGV" and print "Moved $ARGV" if /looking_glass\@telus\.net/' *.BAD I've also corrected several errors in the original code :-) -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]