G'day v_ryan,
Welcome to the monastery.
The '.' in a regex doesn't match a newline unless you use the 's' modifier, so you can lose the '\n' and the '$' - you also don't need the '?'.
The only reason for the grep length is so that you don't pass the initial zero-length string to the map: a slice is shorter.
Running the two dumps for comparison:
... dump { map { /(.+)\n/ => [ /^interesting line (.+?)$/mg ] } grep length, split /^Index: /m }; dump { map { /(.+)/ => [ /^interesting line (.+)/mg ] } (split /^Index: /m)[1,-1] }; ...
gives identical output:
$ pm_golf_1038627.pl { "file1.txt" => [1, 2], "subdir/file2.txt" => ["A1", "A2"] } { "file1.txt" => [1, 2], "subdir/file2.txt" => ["A1", "A2"] }
-- Ken
In reply to Re: Golf challenge: Line-based parsing
by kcott
in thread Golf challenge: Line-based parsing
by v_ryan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |