Re: File::Grep
- From: Xicheng Jia <xicheng@xxxxxxxxx>
- Date: 3 May 2007 10:40:25 -0700
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
.
- Follow-Ups:
- Re: File::Grep
- From: Mumia W.
- Re: File::Grep
- References:
- File::Grep
- From: g4173c
- File::Grep
- Prev by Date: Re: Dynamic DNS management
- Next by Date: Re: Help on expanding variable from sh
- Previous by thread: Re: File::Grep
- Next by thread: Re: File::Grep
- Index(es):
Relevant Pages
|