[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[FWP] odd thing from #perl a few moments ago




guy had problem.  input file looked like this:

    11:59:22  foo bar
           and more foo bar
    12:34:19  this thing is interesting
           and here is mre
           of the stuff
           that is interesting
    12:34:45  boring boring boring
           boring boring boring
           boring and i did I say boring

Each record started with timestamp, and continued along successive
indented lines (one to many lines).

Problem: he wanted just the records with "interesting".

Solution, worthy of FWP:

    @ARGV = qw(/tmp/foo.txt); # where data was
    $n = 0;
    $block[$n += /^\S/] .= $_ while <>;
    @interesting = grep /interesting/, @block;

Bingo.


    <jerji> I don't think I've ever seen so much functionality crammed
    into so few characters.

:-)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe