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

Hi Monks, my web site is down and I can't figure out this problem:

I have an array with five file names which are:

I have a variable called $THREAD, if thread equal "1" during a foreach loop I'm trying to use pattern matching to find the file that begins with 1, not 11, not 12, but 1 which in this case is "1x0.htm". The file at somepoint might be named 1x2, 1x12, ect. But the key is held in the $THREAD variable.

My pattern matching is not working:

I've tried everything, I thought this should work:

$THREAD= "1"
if ($filedir =~ /$THREADx*.htm/) {

Thanks in advance for any help.

Edited by Chady -- retitled from 'Emergency Help'

Replies are listed 'Best First'.
Re: Regex for matching a file name
by etcshadow (Priest) on Sep 06, 2004 at 23:45 UTC
    Make your regexp:
    (emergency question gets somewhat curt, right-to-the point response)
    ------------ :Wq Not an editor command: Wq
Re: Regex for matching a file name
by shenme (Priest) on Sep 06, 2004 at 23:57 UTC
    First, you must explicitly limit what the variable name is that is being substituted, e.g.
    otherwise you are trying to interpolate variable "$THREADx".

    Then you need to make sure the '.' is matching a period. Normally a '.' in an RE is a "match anything" character. So you would need to escape the magic meaning, e.g.

    Then you want the "match anything" for "any length" where you had the asterisk, e.g.

    And... you might want to make sure you don't match "321xBOOM.htm" by saying the string '1' should come at the start of the string, e.g.

    And you might want to wrap it up by checking that the filename _ends_ with the 'htm', e.g.

    Let us know if this helps!

      Thanks to both you Monks, the code works perfectly!!! I certainly appreciate your fast responses.