diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-07-21 18:30:04 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-07-21 18:30:04 +0100 |
| commit | e4ae55c8c264eca50b26938fe3986dc678a8945c (patch) | |
| tree | 7158a2e042f9185502981974174ea87305d4a707 | |
| parent | c2d7ca9d131bc99522e6f4ab81a7d33158b1f27d (diff) | |
| parent | 28587e9186124e41a46d79c44850373c7c38f2be (diff) | |
| download | perlweeklychallenge-club-e4ae55c8c264eca50b26938fe3986dc678a8945c.tar.gz perlweeklychallenge-club-e4ae55c8c264eca50b26938fe3986dc678a8945c.tar.bz2 perlweeklychallenge-club-e4ae55c8c264eca50b26938fe3986dc678a8945c.zip | |
Merge pull request #403 from oWnOIzRi/week017
add task 2 sol
| -rw-r--r-- | challenge-017/steven-wilson/perl5/ch-2.pl | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/challenge-017/steven-wilson/perl5/ch-2.pl b/challenge-017/steven-wilson/perl5/ch-2.pl new file mode 100644 index 0000000000..27167654ce --- /dev/null +++ b/challenge-017/steven-wilson/perl5/ch-2.pl @@ -0,0 +1,35 @@ +#!/usr/bin/env perl +# Create a script to parse URL and print the components of URL. +# https://en.wikipedia.org/wiki/URL +# According to Wiki page, the URL syntax is as below: +# scheme:[//[userinfo@]host[:port]]path[?query][#fragment] +# For example: jdbc:mysql://user:password@localhost:3306/pwc?profile=true#h1 +# scheme: jdbc:mysql +# userinfo: user:password +# host: localhost +# port: 3306 +# path: /pwc +# query: profile=true +# fragment: h1 +# +# usage: $ perl ch-2.pl "jdbc:mysql://user:password@localhost:3306/pwc?profile=true#h1" + +use strict; +use warnings; +use feature qw/ say /; + +# I tried to write something which would work with optional components but it +# is beyond me at the moment. This is my first attempt which works with a +# url containing all the components i.e. the example. + +my $url = $ARGV[0]; + +$url =~ /^(.+):\/\/(.+)@(.+):(\d+)(\/.+)[?](.+)#(.+)/; + +say "scheme: $1"; +say "userinfo: $2"; +say "host: $3"; +say "port: $4"; +say "path: $5"; +say "query: $6"; +say "fragment: $7"; |
