Re: File::Grep



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


.



Relevant Pages

  • Re: File::Grep
    ... I'm trying to get the match string from fgrep with the following code: ... foreach $log (@logfile) { ...
    (comp.lang.perl.misc)
  • File::Grep
    ... I'm trying to get the match string from fgrep with the following code: ... foreach $log (@logfile) { ...
    (comp.lang.perl.misc)
  • Re: Is there a way to query Security Event Log with Filter in C#?
    ... The odd thing is that it works when I change the logfile = 'Application'. ... Wieht Security it retrievs 0 entry. ... ManagementObjectSearcher mos = new ManagementObjectSearcher; ... foreach ) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: File::Grep
    ... If you print out the returned hash ... foreach my $log (@logfile) { ... File::Grep has a bug: it's documentation needs to specify that a list of hash references is returned. ...
    (comp.lang.perl.misc)