Reputation: 167
I have the following url :
Need to proper way to extract the value after "?" Need to find how to explode in perl just the http://example.com part out of the string, and store it in its own variable, split it and save in a variable before passing it.
Upvotes: 1
Views: 411
Reputation: 9256
Is this just a simple split that's required? If so...
my $foo = "http://stagingbugzilla.cpiv.com/html/estVerificationPool/estPendingBugs.php?team_name=General%20administration";
my @values = split( '\?', $foo );
print $values[1];
There are better ways that are more URL aware, but if that does the trick...
Upvotes: 2
Reputation: 3096
An expansion of this answer, includes query_param:
use URI;
use URI::QueryParam;
my $url = 'http://stagingbugzilla.cpiv.com/html/estVerificationPool/estPendingBugs.php?team_name=General%20administration';
my $uri = URI->new( $url );
my @keys = $uri->query_param();
# @keys contains the query parameter names
my $team_name = $uri->query_param( 'team_name' );
# $team_name contains the value of the team_name parameter
Upvotes: 3
Reputation: 101
To extract the value after ?
, use
$url="http://stagingbugzilla.cpiv.com/html/estVerificationPool/estPendingBugs.php?team_name=General%20administration";
($query) = $url =~ /.+?\?(.+)/;
To get the domain name from url and save in the save variable
($url) = $url =~ m{(http://.+?)/};
hope this will help
Upvotes: 1
Reputation:
This regex:
^http://([^/]*)/[^?]*\?(.*)$
when applied to this string:
http://stagingbugzilla.cpiv.com/html/estVerificationPool/estPendingBugs.php?team_name=General%20administration
will yield these captured patterns
1. stagingbugzilla.cpiv.com
2. team_name=General%20administration
The complete code for Perl would be:
$url = "http://stagingbugzilla.cpiv.com/html/estVerificationPool/estPendingBugs.php?team_name=General%20administration";
($domain, $query) = ($url =~ m{^http://([^/]*)/[^?]*\?(.*)$});
With $domain
and $query
being the parts you want, although using a built in library like Pilcrow suggested is probably wiser.
Upvotes: 1