Re: File::Grep
- From: "Mumia W." <paduille.4061.mumia.w+nospam@xxxxxxxxxxxxx>
- Date: Fri, 04 May 2007 10:59:16 GMT
On 05/03/2007 12:40 PM, Xicheng Jia wrote:
On May 3, 11:36 am, g41...@xxxxxxxxxxxx wrote:Hi:
I'm trying to get the match string from fgrep with the following code:
use File::Grep qw (fgrep);
foreach $log (@logfile) {
@match = fgrep { /HOSTNAME/ } "$log";
1) you dont have to add quotation marks with $log.
2) the returned array elements are designed as filehandle-like
objects, not the filenames. If you print out the returned hash
reference, you can easily know how to extract the corresponding
filename..try the following:
foreach my $log (@logfile) {
my @match = fgrep { /HOSTNAME/ } $log;
print $_->{filename} for @match;
# do more stuff
}
Good luck,
Xicheng
Once again, it's proved how valuable Data::Dumper is. I still think File::Grep has a bug: it's documentation needs to specify that a list of hash references is returned.
.
- References:
- File::Grep
- From: g4173c
- Re: File::Grep
- From: Xicheng Jia
- File::Grep
- Prev by Date: Re: 2 array problem
- Next by Date: Re: 2 array problem
- Previous by thread: Re: File::Grep
- Next by thread: Re: File::Grep
- Index(es):
Relevant Pages
|
Loading