Roy Corey (xerhino) wrote in perl,
Roy Corey
xerhino
perl

  • Mood:

Good to be bad.

Ok, this isn't something I would do in code that anyone would ever have to support or modify. This was purely a temporary monitoring script for an ill concieved application that, for dubious reasons, had 30 duplicate directories where logs could be written, depending on the day/time/traffic/phase of the moon/etc.

my @logs = grep {-e $_} map { "/opt/foo/bar/$_/logs/date.log" } 1..30;

I got a map, a grep, and a range operator all on one line and it returns an array of all the log files in the appropriate spots that actually exist. After so long making everything painfully clear this feels decadent. Really, I don't think it's that bad, but I guarentee no one else on my team would understand it. I just had to share with a group that would.

Note: I follow most of the tenets of Damian Conway's "Perl Best Practices" in my professional scripting.
Subscribe
  • Post a new comment

    Error

    default userpic
  • 27 comments