iphone has asked for the wisdom of the Perl Monks concerning the following question:
Use of uninitialized value in pattern match (m//) at orphan_plf.pl line 37
and line 37 is $Hash_filematches{$filename}= grep( /\/\Q$file_name\E#/i, $Hash_filenames{$plf} ); The objective of my program1.Get all the filenames with .plf extension from a directory
2.Store the filename as key and the corresponding lines of it as values in a hash3.For every filename in the hash saved in step 2 grep for a filename in the corresponding lines and save the filename and the corresponding match in another hash and them print the hash
Please help#!/usr/bin/perl -w use strict; use warnings; my %Hash_filenames=(); my %Hash_filematches=(); my $plf; my $start_dir; my $start_dir = \\server1\tools ; my $file_name = "load.c"; opendir(DIR, "$start_dir"); my @plf_files = grep(/\.plf$/,readdir(DIR)); print "PLF FILES\n"; print "@plf_files\n"; foreach my $plf (@plf_files) { chomp($plf); open my $match, '<',"$start_dir\\$plf" or die "could not open '$plf' $ +!"; my @file_lines = <$match>; #Save the filename as key and the lines in the file as value in a hash + $Hash_filenames{$plf}=@file_lines; } closedir(DIR); if ($file_name) { foreach my$filename(keys %Hash_filenames) { #for every key(filename) in the above hash namely #$Hash_filenames #grep for $file_name in the #corresponding values (lines in the file)of the file #and save the match as value and key as filename #in another hash $Hash_filematches{$filename}= grep( /\/\Q$file_name\E#/i, $Hash_filen +ames{$plf} ); } } { local $, = "\n"; print "PRINTING MATCHED HASHES"; foreach my $key ( keys %Hash_filenames ) { my $value = $Hash_filematches{$key}; print "$key => $value\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Grepping for a value in a hash of filenames and printing the matches
by jwkrahn (Abbot) on Oct 27, 2010 at 06:35 UTC | |
by iphone (Beadle) on Oct 28, 2010 at 00:32 UTC | |
|
Re: Grepping for a value in a hash of filenames and printing the matches
by ikegami (Patriarch) on Oct 27, 2010 at 07:20 UTC | |
|
Re: Grepping for a value in a hash of filenames and printing the matches
by suhailck (Friar) on Oct 27, 2010 at 05:52 UTC | |
|
Re: Grepping for a value in a hash of filenames and printing the matches
by umasuresh (Hermit) on Oct 27, 2010 at 12:52 UTC |