Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

by kcott (Archbishop)
on May 14, 2017 at 06:02 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1190254]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-25 18:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found