nop has asked for the wisdom of the Perl Monks concerning the following question:
package FileName; use FindBin; use lib "$FindBin::Bin/modules"; use Common; use Data::Dumper; use strict; sub name { my ($type, $relativeto, $attrib) = @_; $attrib = {} if !defined($attrib); die 'attrib must be hash' unless ref($attrib) eq 'HASH'; my %a = %$attrib; my $fname = ''; if ($type eq 'root') { $fname = $ENV{HTMDIR} . "/dash.htm"; } elsif ($type eq 'graph') { $a{biz} = 'ALL' if $a{biz} eq '*'; $fname = $ENV{HTMDIR} . '/graphs/graph-' . $a{stat} . "-" . $a{biz} . ".png"; } elsif ($type eq 'statbizchan') { $a{biz} = 'ALL' if $a{biz} eq '*'; $a{chan} = 'ALL' if $a{chan} eq '*'; $fname = $ENV{HTMDIR} . '/details/stat-' . $a{stat} .'-' . $a{biz} . "-" . $a{chan} . ".htm"; } elsif ($type eq 'statbizchandata') { $a{biz} = 'ALL' if $a{biz} eq '*'; $a{chan} = 'ALL' if $a{chan} eq '*'; $fname = $ENV{HTMDIR} . '/details/data-' . $a{stat} . "-" . $a{biz} . "-" . $a{chan} . ".htm"; } elsif ($type eq 'sql') { $fname = $ENV{HTMDIR} . '/details/sql-' . $a{stat} . ".htm"; } elsif ($type eq 'week') { $fname = $ENV{HTMDIR} . "/reports/" . $a{nickname} . "-" . $a{baseday} . ".htm"; } else { die "unknown type=$type"; } die 'fname not set' . Dumper(\@_) unless $fname; # wants it as a filename return $fname if ($relativeto eq ''); # wants it as a URL relative to filename $relativeurl debug3 "relto=$relativeto\n"; $relativeto = &asURL($relativeto); # make it a URL debug3 "relto=$relativeto\n"; debug3 "fname=$fname\n"; $fname = &asURL($fname); # make it a URL debug3 "fname=$fname\n"; # only want the directory of base $relativeto =~ s/[^\/]+$//i; debug3 "relto=$relativeto\n"; # now knock this off off $fname $fname =~ s/$relativeto//; debug3 "returning fname=$fname\n"; return $fname; } sub asURL { my ($fname) = @_; $fname =~ s/$ENV{HTMDIR}/$ENV{URLPATH}/i; return $fname; } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: URL path shortening
by merlyn (Sage) on May 24, 2002 at 00:25 UTC | |
|
Re: URL path shortening
by grinder (Bishop) on May 23, 2002 at 21:44 UTC | |
|
Re: URL path shortening
by nop (Hermit) on May 24, 2002 at 02:27 UTC |