
BillKSmith
Veteran
Oct 30, 2015, 12:59 PM
Post #3 of 3
(10453 views)
|
Re: [biswa_pradhan] comparing regex with variable
[In reply to]
|
Can't Post
|
|
The strange final slash has nothing to do with your problem. (Windows will accept either forward or backward slash) If you had used "use warnings;", you would have received a message alerting you to the problem. The message is correct, but not very helpful. Strings are not quite the same as regexes. In your regex, you correctly escape the backslashes because you intend them to be used literally. You escape the forward slash to prevent a conflict with the match delimiter. In your second example, you want to put this regex in a string. In order to put two consecutive backslashes in a string, you must escape both of them. It is not necessary to escape the forward slash, because there is no conflict.
#my $plfolder = "D:\\All\\Mine\/"; my $plfolder = 'D:\\\\All\\\\Mine/'; A better solution is use the Regex quote like operator (qr).
my $plfolder = qr/D:\\All\\Mine\//; Good Luck, Bill
|