Esteemed Monks,
I originally had a boring old loop to iterate through text line by line to pull out relevant bits. It wasn't very Perlish. So I came up with this instead:
#!/usr/bin/env perl use warnings; use strict; use Data::Dump qw/dump/; $_ = do { local $/; <DATA> }; dump { map { /(.+)\n/ => [ /^interesting line (.+?)$/mg ] } grep length, split /^Index: /m } __DATA__ Index: file1.txt Bunch of junk interesting line 1 more junk interesting line 2 more junk Index: subdir/file2.txt interesting line A1 still more junk interesting line A2 last of the junk
Output: { "file1.txt" => [1, 2], "subdir/file2.txt" => ["A1", "A2"] }
My question is, is there a way to further shorten the code within the dump { } braces, producing the same result? Whitespace and the literal strings don't matter, nor does the sample code outside the dump { }, nor is efficiency a concern. I feel like I'm missing something obvious.
In reply to Golf challenge: Line-based parsing by v_ryan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |