perl_mystery has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: GREP value not initialized
by Eliya (Vicar) on Feb 20, 2011 at 09:39 UTC

    Unless you tell us what's in %Hash_plfdata and $file_name (some sample case where you think something should match is sufficient), we cannot really offer any help beyond "the grep condition presumbly is never true...".

    This, for example, works for me (except for the C/C++-style comment in your code, to be precise):

    my %Hash_plfdata = ( foo => ["/bar#"] ); my $file_name = "bar"; ... __END__ BASE p4 path:/bar#
Re: GREP value not initialized
by chrestomanci (Priest) on Feb 20, 2011 at 17:51 UTC

    I think I can see the bug in your grep code.

    In your first regular expression, you have written:

    /\/\Q$file_name\E#/i

    in other words, you are trying to match a filename, and you have sensibly quoted it, however you have added a hash char to the end. Was this international? A hash won't denote a comment unless you set the /x regexp option.

    A few other comments:

    You can reduce the 'leaning toothpicks effect' by choosing a different regexp delimiter. eg:

    qr:/\Q$file_name\E:i

    Also the second regular expression looks to be matching a file extension. If that is what you are doing, you might want to add an anchor for the end of the string. eg:

     /\.plf^/

Re: GREP value not initialized
by Anonymous Monk on Feb 20, 2011 at 09:28 UTC
Re: GREP value not initialized
by wind (Priest) on Feb 21, 2011 at 18:56 UTC
    For a couple additions to chrestomanci's advice:
    1. 1) I'd recommend that you use values instead of keys since you're ignoring the key data.
    2. 2) Also, be sure to use the $ anchor instead of ^ for the end of string boundary
    foreach my $plf_vals (values %Hash_plfdata) { my ($base_p4path) = grep {m{/\Q$file_name\E}i && !m{\.plf$}} @$plf +_vals; print "BASE p4 path:$base_p4path\n"; }