Re: [^/]* Is Not Working

2018-03-17 Thread John SJ Anderson


> But this one in its place does not work:
> if ($link =~ m/\/([^/]*)$/) { # Oddly this does not work

You still need to escape the `/` inside the character class.

This works in my testing: `m/\/([^\/]*)$/`.

IMO this is a case where an alternative delimiter for `m//` — such as the `#` 
in your working example — is a better approach. 



chrs,
john.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




[^/]* Is Not Working

2018-03-17 Thread Mike Flannigan


This line works fine:
if ($link =~ m#/([^/]*)$#) {

But this one in its place does not work:
if ($link =~ m/\/([^/]*)$/) { # Oddly this does not work

Gives error:
Unmatched [ in regex; marked by <-- HERE in m//([ <-- HERE ^/ at 
csvtopo24.pl line 74.



I think it has to do with the "[^/]*".
Anybody have an explanation for this?


Mike


Simplified code:

#!/usr/bin/perl

use strict;
use warnings;

my $link = '/tree';

#if ($link =~ m/\/([^/]*)$/) { # Oddly this does not work
if ($link =~ m#/([^/]*)$#) {
    my $match = $1;
    print "\nIt worked - $match.\n\n";
}

__END__

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/