in reply to Re^2: need help in building dynamic regular expression
in thread need help in building dynamic regular expression

Wrap your code in <code> tags. Separate your paragraphs with <p> tags. Given that you are asking for help, it is incredibly rude of you to make me go through and reformat your code. For example, note how all your array indices have been transformed to links. In order to run your code, I have to go through and add square brackets by hand. Do you really value my time so little that you cannot type a few extra letters? I am a very patient person (as are most people on this site), but your lack of consideration is wearing my patience thin.

Your code is horribly formatted from your post and you have not given me the contents of C:\sun\pat, so some of my comments may be off point.

  1. You are performing an open without testing if it worked. Perl will fail silently if something went wrong with the open. An open statement should look like open FH, "<", "C:\\sun\\pat" or die "Open failure: $!";. See perlopentut.

  2. You don't seem to understand how string interpolation works in Perl - you have a lot of unnecessary concatenation. See Quote and Quote like Operators in perlop

  3. You appear to be parsing your strings character by character. There is almost never a reason to do this in Perl. You could accomplish your task with regular expressions (perlretut), but if you are working with paths, it is always easier to use someone else's well-tested code. As I posted originally, File::Spec does everything you need.