Another way to grep something from files. By BK
BEGIN { *::find = \&find } sub find{ grep{ grep &{$_[0]}($_), ( open IN, $_ and <IN> ) } map{ opendir DIR, $_ and &{sub{ map $_[0].$_, @_[1..$#_] }}($_, readdir DIR) } @_[1..$#_] }

Replies are listed 'Best First'.
Re: grep text (alternative)
by merlyn (Sage) on Mar 28, 2005 at 20:53 UTC
    Are you sure this doesn't belong in Obfuscated Code? I'm still scratching my head after five minutes.

    This looks like a lot of cargoculted snippets, mostly stolen from ObfuPerl or Golf. I mean, I have been accused of writing short cryptic code before, so for me to say that to you, I hope you understand the significance of that. {grin}

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      Five minutes? Reading it backwards, it's clear and obvious1 that it's a perlish implementation of grepping through all files in a series of directories. It takes a sub as the first param, which is used to determine if a given line matches or not, the rest of the params are the directory names to look in. It returns the list of files that have a match.

      1 No, not really.

      Good idea, let me move it.
        It's surely not easy to read!