-1

Suppose I have 3 variables.

my $val1 = './f1/abc.txt'; #f1 is the folder where abc.txt resides.

my $val2 = './f1/def.txt';

my $val3 = 'gh.txt';

I am facing an issue while reading the './f1/' part.

if ($val1 =~ m/^a.*\.txt$/ or  $val2 =~ m/^d.*\.txt$/) { print $val3; }

this doesn't work with the folder name. Please help.

Jens
  • 67,715
  • 15
  • 98
  • 113
GSG
  • 71
  • 2
  • 10
  • This question has absolutely nothing to do with forward slashes. It has to do with you incorrectly using the `^` anchor. `^` means "beginning of the string". You are asking Perl if `$val` matches: "beginning of string, a, 0 or more of any character, period, txt, end of string". It doesn't. The `a` in $val1 is not adjacent to the beginning of the string, it is in the middle of the string. Same thing for `$val2` - the `d` does not come at the beginning of the string. Remove the `^` anchors. – Paul L May 16 '16 at 13:11

1 Answers1

0

You can find the forward slashes in "./f1/" with this escape sequence:

\/
The SE I loved is dead
  • 1,517
  • 4
  • 23
  • 27
  • Thanks mate. I was just using a double forward slash (\//)while scripting. Thanks for your help. – GSG May 15 '16 at 21:19