Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Can figure out a way to get File::Grep's fgrep to chomp matches

by kcott (Bishop)
on May 14, 2017 at 06:02 UTC ( #1190254=note: print w/replies, xml ) Need Help??


in reply to Can figure out a way to get File::Grep's fgrep to chomp matches

G'day Lady Aleena,

I haven't used that module before, so there may be a better way of doing this; however, the following achieves what you appear to want.

#!/usr/bin/env perl use strict; use warnings; use File::Grep qw(fgrep); use Data::Dumper; my @line = map { chomp $_ for values %{$_->{matches}}; $_ } fgrep { /^ +[2-6] .+$/ } *DATA; print Dumper(\@line); __DATA__ 2 foo 3 bar 4 baz 5 qux 6 quux 7 thingy 8 widget

Output:

$VAR1 = [ { 'count' => 5, 'matches' => { '3' => '4 baz', '4' => '5 qux', '1' => '2 foo', '5' => '6 quux', '2' => '3 bar' }, 'filename' => *::DATA } ];

— Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1190254]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2019-09-18 05:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (222 votes). Check out past polls.

    Notices?