Imaginary Billboards » Stupid perl tricks (that would be better in something else)

Stupid perl tricks (that would be better in something else)

Posted by Chris on August 20th, 2009 filed in sysadmin

Hey, 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!


4 Responses to “Stupid perl tricks (that would be better in something else)”

  1. Chas. Owens Says:

    I can’t help but golf this:

    perl -le ‘for(@ARGV){print$c=”echo repair table $_ | mysql -uroot mydb”;`$c`}’ things whosit mrmr

  2. Chas. Owens Says:

    Shaved another two characters off:

    perl -le ‘map{print$c=”echo repair table $_ | mysql -uroot mydb”;`$c`}@ARGV’ things whosit mrmr

  3. Matt S Trout Says:

    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 🙂

  4. admin Says:

    I think that is prettier. When you’re dealing with a bunch of python guys, that’s suprisingly important. Thanks all!

Leave a Comment