How to get the current URL in Perl
Posted by Dexter Nelson: Monday, February 3, 2014 (4:40 PM)
How do you get the current url in perl?
Well? I didn't want to use LWP or CGI or any of that, and environment variables don't give you the full URL, so here is the solution I came up with to get the current url in perl.
## CODE SNIPPET ##
my $page_url = 'http';
if ($ENV{HTTPS} = "on") {
$page_url .= "s";
}
$page_url .= "://";
if ($ENV{SERVER_PORT} != "80") {
$page_url .= $ENV{SERVER_NAME}.":".$ENV{SERVER_PORT}.$ENV{REQUEST_URI};
} else {
$page_url .= $ENV{SERVER_NAME}.$ENV{REQUEST_URI};
}
## END CODE SNIPPET ##
Thanks to some creative concatenation, I can use the $page_url variable whenever I need to get the current url of the page in perl.
Leave a comment below and let me know if this worked for you as well.
By the way...
Are you interested in learning how I make extra money blogging? (I use the money to pay for licenses and stuff so I don't have to come out of pocket)
What would you do with it?