I am getting the following warning while running my code

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 program

1.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 hash

3.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"; } }

In reply to Grepping for a value in a hash of filenames and printing the matches by iphone

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.