On the line where you say:
$key="C:\abc\dfg";Your string $key doesn't actually have any backslashes ('\') in it. When in double-quotes, the backslash is a special character that combines with the next character to tell perl what to insert into the string. For example, "\t" indicates a tab character (a byte containing 09H), and "\n" tells perl to start a new line (a byte containing 0DH). So the string: "dog\n\tcat" tells perl to build a string holding "dog", a newline, a tab character, and "cat". There are no backslashes in the string.
You can correct this problem by putting the value in single quotes, e.g.,
$key='C:\abc\dfg';or you can tell perl you really want a backslash (by using two backslashes!):
$key="C:\\abc\\dfg";Alternatively, you can use the forward slash: In most cases, Windows/DOS is happy with forward slashes in file names. Perl and Unix are happy with it too, so that's what I do nearly everywhere:
$key="C:/abc/dfg";So, the long and short of it is that you're not matching because you have no backslashes in your string, along with any other problems the expression might have.
...roboticus
FYI: Be sure to preview your post and update the formatting before pressing the "create" button! Also, you can go back and update a post to add code tags, rather than start a new one.
Update: Fixed byte value for tab from "08H" to "09H". Thanks to bart for the catch!
Update: Fixed order of tab and newline in example text. Thanks to johngg for noticing that one.
In reply to Re^3: unable to fomulate right regular expression to fetch the intermediate and last word from a line (windows path) using delimiter "\"
by roboticus
in thread unable to fomulate right regular expression to fetch the intermediate and last word from a line (windows path) using delimiter "\"
by suniln
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |