Just another way to do it:
use strict;
use warnings;
use URI;
my $uri = URI->new( $ENV{REQUEST_URI} );
my $page = ($uri->path_segments)[-2];
The problem with this code is that the return value of
URI::path_segments() changes if the URI contains a trailing slash or not. You could improve the robustness at the expense of added complexity by using
map to squash the return of
URI::path_segments() however:
my $page = (map $_ ? $_ : (), $uri->path_segments)[-1];
Kinda defeats the purpose of using methods from a module however. ;)