The aforementioned example doesn't actually convert the forward slash. You could try URI escaping everything your file system disallows in a filename. On a Windows system, that would be \/:*?"<>|. The following shows how you can get valid, but funky looking filenames:

use strict; use URI::Escape; my @tests = ( "1/15/99-Bob.pdf", "test.txt", '\\/:*?"<>|' ); for ( @tests ) { print uri_escape( $_, ':\\\\\/*?"<>|' ), "\n"; }

That outputs the following:

1%2F15%2F99-Bob.pdf test.txt %5C%2F%3A%2A%3F%22%3C%3E%7C

This may not be your best options, but have you thought of creating directories like the following?

wwwroot -- documents --- 1 -- 25 -- 99 | -- 2 | -- 3

You actual pdf could then be named -Bruck.pdf and the path would work fine. Of course, I'd probably put the year first, but it does make for a handy organizational structure if you'll be working with many files.

One concern with your approach may be portability. Is that an issue? Do you want this to work with 8.3 filenames? Do all file systems allow for percent signs in filenames (though I don't know of any which don't).

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.


In reply to (Ovid) Re: Packing HTML Paths by Ovid
in thread Packing HTML Paths by skreuzer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.