# Sometimes you need to change something in a bunch of files at once. # These are some command-line ways of doing that. # For universal replacement (in all files down from the current directory): find ./ -type f -exec perl -pi -e \'s/stringtofind/stringtoreplacewith/g\' {} ; # To do all ".php"s, for example: find ./ -type f -name *.php -exec perl -pi -e \'s/stringtofind/stringtoreplacewith/g\' {} ; # To find/replace in just the present directory: perl -pi -e \'s/stringtofind/stringtoreplacewith/g\
code
ftp with perl
#!/usr/bin/perl -w # Yet another time when dependence on libraries bit me, I had to see if # I could manage an ftp script using the core perl libraries, so I wasn\'t # dependent on Net::FTP being present in the same form on the system. # This is just my proof of concept, developed with telnet and the perl # cookbook. use IO::Socket; $remote_host = "remotehost"; $remote_port = 21; $user = "username"; $pass = "password"; $socket = IO::Socket::INET->new(PeerAddr => $remote_host, PeerPort => $remote_port, Proto => "tcp", Type => SOCK_STREAM) or die "Couldn\'t connect to $remote_host:$remote_port : $@n"; # AUTHENTICATION $answer = < $socket>; print "$answer"; print $socket "user $usern"; $answer = < $socket>; print "$answer"; print $socket "pass $passn"; $answer = < $socket>; print "$answer"; # DIRECTORY NAVIGATION print $socket "pwdn"; $answer = < $socket>; print "$answer"; # QUIT print $socket "quitn"; $answer = < $socket>; print "$answer"; # and terminate the connection when we\'re done close($socket);
smtp.pl
#!/usr/bin/perl -w use Mail::Mailer; $smtp = Mail::Mailer->new("smtp","Server","smtp.server"); print "To: "; $to =; chomp($to); print "Subject: "; $subject = ; chomp($subject); print "Body:n"; while ($line = ) { last if $line eq ".n"; $body .= $line; } chomp($body); print "Opening SMTP connection...n"; $smtp->open({ "From" => "hmm@woolgathering.cx", "To" => $to, "Subject" => $subject }); print $smtp $body; print "Sending email...n"; $smtp->close() or die "Can\'t close mailer: $!"; print "Mail sent.\n";