in reply to Making the later front slash "/" optional

next if $file =~ /^\/?$location/;
makes the front slash optional.

update: See the exemplary code below, which will result in OK2 OK3 OK4:

my $s1 = "abc"; my $s2 = "/abc"; my $all = "/abc"; print "OK1\n" if $all =~ /^$s1/; print "OK2\n" if $all =~ /^$s2/; print "OK3\n" if $all =~ /^\/?$s1/; print "OK4\n" if $all =~ /^\/?$s2/;

update 2: Thanks for the hint davido. Now that you point it out, I see that I misinterpreted front and later. @OP: please use the solution provided by davido instead!

Replies are listed 'Best First'.
Re^2: Making the later front slash "/" optional
by davido (Cardinal) on May 03, 2011 at 07:38 UTC

    I could be mistaken here, but I think OP is saying "front slash" when he means "forward slash", and "later" means... "trailing." In other words, my assumption is that he wants to make the trailing forward-slash optional.


    Dave