in reply to Packing HTML Paths

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.

Replies are listed 'Best First'.
Who came up with MM/DD/YY anyway ?(was: Re: (Ovid) Re: Packing HTML Paths)
by Corion (Patriarch) on May 22, 2001 at 21:46 UTC

    If we're to use this as an organisational structure, I recommend using either european/continental date style (DD/MM/YY) or even better, the unnamed but alphabetically sorting style YYYY/MM/DD. This way, old stuff can easily be found and put on tape.

    Update: Of course, Ovid already said that. People who can read (and actually do) have an advantage I guess.

      Just general rambles about your reply (which is merely a cheap way to mention something I did in VBScript :)

      I prefer YY/MM/DD or YYYY/MM/DD since sorting is much easier. It may not seem like a big deal to Perl users, but imagine if others are forced to manipulate data in other languages, such as VBScript, which doesn't have native sorting.*

      In any event, even with Perl's robust sorting abilities, having a straight-forward sort on the dates is much easier to read than a lot of weird maps or greps or other things. Of course, if I have complex sorting, I usually stick it in a function with a descriptive function name.

      Cheers,
      Ovid

      * I kind of feel sorry for some of the VBScript programmers I left behind. I am so used to shift, pop, sort, and so many other handy tools to use with lists and arrays that I wrote a "Perl functions" library in VBScript. Much of my VBScript code read like "baby Perl" (though only in parts where I thought the overhead wouldn't kill a language that was not designed for such functions).

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

      It isn't unamed, it is ISO 8601. It is the internationally standardized date format (except the standard specifies that you use "-" instead of "/", which is a good idea as it is easier to read that way ["/" looks too much like a "1" to too many cases] and also doesn't require escaping).

      See international standard date format.

              - tye (but my friends call me "Tye")