#! /usr/bin/perl import lilparser; my @headers = qw(Protocol Host Port Path Parameters); my @msg = (); @msg = &lilparser::parse($ARGV[0]) unless !@ARGV; for (my $i = 0; $i <= $#msg; $i++) { print $headers[$i] . " :: "; print $msg[$i] . "\n"; print "--------------------------------------------\n"; } print "\n"; exit 0; { package lilparser; use strict; BEGIN { use Exporter(); use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = 1.00; @ISA = qw(Exporter); @EXPORT = qw(); %EXPORT_TAGS = (); @EXPORT_OK = qw( &parse ); } use subs @EXPORT_OK; sub parse($) { my $uri = shift; my ($protocol, $host, $port, $path, $params); # $1 $2 $3 $4 # protocol host port path # if ($uri =~ m#^(?: ([^:]+)(?:://) ([^/:]+) (?:(?::)(\d+))? )? (.*)$#x) { # # $1 $2 $3 $4 $5 # protocol host port path params if ($uri =~ m#^(?: ([^:]+)(?:://) ([^/:]+) (?:(?::)(\d+))? )? ([^?]*)(?:\?(.*))?$#x) { $protocol = $1 || 'http'; $host = $2 || 'oswego.edu'; $port = $3 || '80'; $path = $4 || '/'; $params = $5 || ''; return ($protocol, $host, $port, $path, $params); } } 1; END { } }
[script of sample run]