Stupid perl tricks (that would be better in something else)
Posted by Chris on August 20th, 2009 filed in sysadminHey, when you are really comfortable with a hammer, why not use it to open that beer too?
I have a giant (and I mean giant) dataset that I have to load and do some things with the data, then put it somewhere else. Once I managed to corrupt almost every single table. So, have to repair them all.
perl -e 'foreach $a qw{things whosit mrmr}{$cmd=qq{echo "repair table $a" | mysql -uroot mydb};print "$cmd\n";`$cmd`;}'
Silly use for the perls, but – it really works!

August 20th, 2009 at 4:11 pm
I can’t help but golf this:
perl -le ‘for(@ARGV){print$c=”echo repair table $_ | mysql -uroot mydb”;`$c`}’ things whosit mrmr
August 20th, 2009 at 4:13 pm
Shaved another two characters off:
perl -le ‘map{print$c=”echo repair table $_ | mysql -uroot mydb”;`$c`}@ARGV’ things whosit mrmr
August 21st, 2009 at 5:46 am
Meh.
perl -e ‘print q{echo “}.join(“\n”,map “repair table $_;” @ARGV).q{“| mysql -uroot mydvb};’ things whosit mrmr
is longer, but prints prettier shell commands.
When generating code, always try and make the generated code pretty, even at the cost of a little more ugliness in the generator – you’ll thank yourself when you have to debug the output.
(and yes, I know everybody else was just playing, but this still strikes me as a more elegant solution
August 21st, 2009 at 8:44 am
I think that is prettier. When you’re dealing with a bunch of python guys, that’s suprisingly important. Thanks all!