[LA.pm] perl/file path on mac x

David Heayn david at cloudgraphics.com
Sat Feb 18 22:15:00 PST 2006


I am having a miserable time trying to figure out how perl sometimes 
can and can't read a string with a non-POSIX (?) compliant file path.

I'm trying to develop a cross-platform script for animators who 
needed to know not only how many frames had been rendered to a 
directory, but also quickly calculate estimated finish time, average 
frame render... blah blah blah.

The trouble arises when a mac user (maybe others) tries to point the 
script to watch "current directory" which lives in:

/users/bob/files and stuff/current render


Now, it's very easy to:

% cd ../dir 2
because mac's terminal program escapes the blank if the end user 
drags and drops the file into the cli,
% cd /xzy/dir\ 2

If I have a perl script going and it asks for input
% perl watcher.pl
% Which directory to watch?
I can then drag a directory right into the terminal, *have it 
escaped* automatically via mac x... but it "gets lost" within perl. I 
debugged it. I saw the escaped dir path, but perl failed every time 
it tried to switch directories. Somehow it seems to "unescape" in 
memory before it gets to it's final destination, or become useless 
when perl tries to chdir()


Now, I'm also working on something similar with regards to moving 
paths based on user input. Because I don't know how to correctly pass 
a file path correctly I did this hack for a HTML based gallery 
fixer-script. Hardcode a path in the script...

#!/bin/usr/perl -w
use strict;
my $w = "360"; # width of the PDF
my $h = "465"; # height of the PDF
my $bor = "1"; # border of the PDF
my $path1 = 
"/Users/dave/Documents/T.L/Publish-\>Web/web-content/PDF/1/index.html";
my $path2 = "/Users/dave/Documents/T.L/ 
Publish-\>Web/web-content/PDF/2/index.html";

print "*****  PDF -> WEB cleanup program\n";
print "A - $path1\n";
print "B - $path2\n";
print "Index.html to modify?";
my $choice = <STDIN>;
my $fileLoc;
if ($choice eq "A") {$fileLoc = $bus;}
if ($choice eq "B") {$fileLoc = $mar;}
###########
#open(READFILE, 
"/Users/dave/Documents/T.L./Publish-\>Web/web-content/PDF/1/index.html") 
or die "Can't open file!!! \n";
open(READFILE, "$fileLoc") or die "Can't open file!!! \n";
my $firstRead = <READFILE>;
close(READFILE);

##################################

No warnings.
Printing to screen works.
Take input and branching works.
But, using the already hardcoded path does not (if it's in a 
variable). I get a failure.
The paths were copied from the command line, "apple escaped" then 
inserted into my script, and they do exist on the hard drive, I 
checked them. I do have a directory named "Publish->Web", but, again, 
it is escaped... and therefore the problem is something else.

In the above script, there is a commented out line, 
#open(READFILE)...   which works but I want a way to pass a file path 
via variables to open(). I also have to destroy my choice A or B 
code, and manually edit the script before it runs. :(

My first guess is I have to do some escaping. But as I said before, 
they are escaped when viewed in the debugger. Any insights would be 
wonderful.




David Heayn * http://www.cloudgraphics.com * 213/925.3283


More information about the Losangeles-pm mailing list