Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: How to get current URL with Query String

by Your Mother (Chancellor)
on May 10, 2013 at 16:51 UTC ( #1032984=note: print w/replies, xml ) Need Help??


in reply to How to get current URL with Query String

Another.

use strictures; use CGI ":standard"; use URI; my $requested = URI->new( CGI::url() ); $requested->query( $ENV{QUERY_STRING} || $ENV{REDIRECT_QUERY_STRING} ) if url_param(); print header(), start_html(), h1("OHAIURI"), blockquote($requested), end_html();

Replies are listed 'Best First'.
Re^2: How to get current URL with Query String
by thewebsi (Scribe) on May 10, 2013 at 20:06 UTC
      I wanted to quickly input here. I've been using this, especially where I have apps that run on both http:// and https:// In my case where I use OOP it's usually a subroutine in the main package, but this works just as well, calling the $page_url variable. Some smart concatenation, no additional modules, strictly native...
      my $page_url = 'http'; if ($ENV{HTTPS} = "on") { $page_url .= "s"; } $page_url .= "://"; if ($ENV{SERVER_PORT} != "80") { $page_url .= $ENV{SERVER_NAME}.":".$ENVSERVER_PORT}.$ENV{REQUEST_U +RI}; } else { $page_url .= $ENV{SERVER_NAME}.$ENV{REQUEST_URI}; }
      what do you think?
        if ($ENV{HTTPS} = "on") {

        Already shows a problem with this sort of approach (copying and pasting the “same” snippet around). I don’t doubt you have it right somewhere but that above is a bug (you need eq and you should probably also normalize case with lc). It will always say the URL is https as is.

        String concatenation is, to me, code smell. The “no additional modules” shtick can be paraphrased to: no help from experts who have been solving and testing this exact problem against edge cases for 20 years and will continue to do so as the standards are updated.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1032984]
help
Chatterbox?
Discipulus was a question
[GotToBTru]: current job found me
Discipulus is so lucky to have a decent job, with old, favorable contract, done before the ultralibersm arrived in Eataly
[Lady_Aleena]: Has anyone here ever use pcregrep? I can't seem to get the --include regex right. --include=*.p[lm] works in grep but not pcregrep.
[erix]: to lift your spirits, here is some more happy Randy news...
[Lady_Aleena]: The reason I would like to use pcregrep is because it can do multiline searches supposedly.
[perldigious]: What are your criteria for looking Tanktalus? What things must a job have for you to consider it? And where are you in your career? Start, middle, or end?
[erix]: are there any regex-engines that do not do multiline?
[Lady_Aleena]: erix, grep doesn't.
[Lady_Aleena]: Linux grep that is...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (9)
As of 2017-05-23 19:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?