diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-03-15 19:32:08 +0100 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-03-23 18:03:41 +0100 |
| commit | 51839d5ae944b3fb4c880f825050e0317067b8e9 (patch) | |
| tree | db84414ca59dbc2cc8f8b886790323250479d5a6 | |
| parent | 27746120072266d19b4aba4970e75098b6995b7d (diff) | |
| download | perlweeklychallenge-club-51839d5ae944b3fb4c880f825050e0317067b8e9.tar.gz perlweeklychallenge-club-51839d5ae944b3fb4c880f825050e0317067b8e9.tar.bz2 perlweeklychallenge-club-51839d5ae944b3fb4c880f825050e0317067b8e9.zip | |
Challenge 017 task 2
| -rwxr-xr-x | challenge-017/jo-37/perl/ch-2.pl | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/challenge-017/jo-37/perl/ch-2.pl b/challenge-017/jo-37/perl/ch-2.pl new file mode 100755 index 0000000000..82ddec6866 --- /dev/null +++ b/challenge-017/jo-37/perl/ch-2.pl @@ -0,0 +1,40 @@ +#!/usr/bin/perl + +use v5.16; +use warnings; + +### Input and Output + +main: { + my %urlparts = parse_url(shift); + say "$_: $urlparts{$_}" for keys %urlparts; +} + + +### Implementation + +# Do not verify the individual parts' syntax. + +sub parse_url { + shift =~ m{^ + (?<schema>.+?): # schema is mandatory + (?:// + (?: + (?<userinfo>.+?)\@ # userinfo is optional + )? + (?<host>[^/:]+?) # host is mandatory in authority + (?: + :(?<port>[^/]+?) # port is optional + )? + (?=/|$) # path must start with / if authority exists + )? + (?<path>[^?]*?) # path is mandatory, but may be empty + (?: + \?(?<query>[^#]+?) # query is optional + )? + (?: + \#(?<fragment>.*) # fragment is optional + )? + $}x; + (%+); +} |
