From: C.DeRykus on
On Feb 6, 5:56 am, "Dr.Ruud" <rvtol+use...(a)xs4all.nl> wrote:
> C.DeRykus wrote:
> > ( $name ) = $path =~ m{  / ([^/]*) \z }x
>
> That $name will end up false if there is no slash in $path.
>
> perl -Mstrict -le '
>    for my $path (undef, "", "test", "test/123") {
>      my ($name) = $path =~ m~([^/]+)\z~;
>      print defined($name) ? "<$name>" : "undef";
>    }
> '
> undef
> undef
> <test>
> <123>
>
> But you should just use File::Basename for this.
> (beware, the module name was grossly misspelled by OP)

I could be wrong but the OP sounded more interested in
how regex lookbehind could be used in a specific case
than generating a drop-in replacement for File::Basename.
But, I agree it's worth noting the limitations and correct
spelling.


--
Charles DeRykus