Geekuprising.com Logo
Home Youth Debate About Us Clients Services Technologies Code
You are here:: Code > Short and Sweet
spacer
Browse

Almost pointless little snippets of code. Enjoy!

Find the longest word

So this isn't that useful (or efficient) but I thought it was cool anyway. It rips through a file, finds the longest word and prints it out.

#!/usr/bin/perl;
open(INFILE, $ARGV[0]) or die "File Not Found, or you didn't give me one. Shmuck. \n";
@sorted = sort {length $a <=> length $b} map {split(/\s+/,$_)} <INFILE>;
print pop @sorted;
close INFILE;

Find apache child lifetimes

I do a lot of mod_perl optimization and server management.

To keep apache child size growth in check, I use Apache::SizeLimit to keep track of how much unshared memory each child uses, reaping them when they grow too large. When it reaps a child it logs it to the apache error_log.

This line in my /etc/crontab file gives me a daily report on how long my apache children are living, so I can review it quickly to see if there are any problems.

20 1 * * * root perl -e 'print "Apache children lived for:\n";foreach(`grep -i big /var/log/apache/error_log`){@a=split(/\s+/,$_);print $a[(@a-2)]."\n"};'

Copyright 2004 © Geekuprising Internet Consultants