Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Guys,appreciate any inputs on this. I want to have an "hash array" of files content Is there a way I can achieve this?
1.Grep for a folder(there are array of folders) in array of file contents
2.Push the file name and the matching grep line into another hash
#!/usr/bin/perl -w use strict; use warnings; my @folders= ("data,power"); my @array=("./data.h","./power.h"); my $folder; my %files_content; my %grep_lines; foreach $file (@array) { open my $fh, $arr or die $!; $files_content{ $file } = <$fh>; close $fh; } foreach $folder (@folders) { foreach $filename (keys %files_content) { push @{ $grep_lines{ $filename } }, grep (/$folder/i, @{ $files_co +ntent{ $filename } }); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Creating a array hash with all file content
by Corion (Patriarch) on Apr 30, 2011 at 06:19 UTC | |
by Anonymous Monk on Apr 30, 2011 at 06:43 UTC | |
by philipbailey (Curate) on Apr 30, 2011 at 10:13 UTC | |
|
Re: Creating a array hash with all file content
by John M. Dlugosz (Monsignor) on Apr 30, 2011 at 10:09 UTC |