#!/usr/bin/perl -w # # $Id: path2uri,v 1.1 2007/08/09 00:34:59 vogelke Exp $ # #< path2uri: encode a pathname as a local URI. use Cwd 'realpath'; use strict; if (@ARGV) { foreach (@ARGV) { encode($_); } } else { while (<>) { chomp; encode($_); } } exit(0); sub encode { my $path = realpath(shift); # Had to add '/' to the list of safe characters, # or the first slash would be encoded. $path =~ s/([^a-z0-9\/\-_.!~*'()+])/sprintf "%%%02X", ord($1)/gei; print "file://$path\n"; }