[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl-AnyPerl] Re: works as script, not as droplet



Recently I wrote:
>
>The script below is driving me nuts. I created a droplet to add
>the DOCTYPE line to an HTML file awhile back... I tested the script 
>assigning a list of file names to @ARGV and then commenting the line 
>when I created a droplet, which gets its files from @ARGV. What is 
>happening is that the script is merely writing the file names and 
>lengths to the log file and exiting... {Even though the file name 
>was short}

Here's that original code snippet for testing file name length:

>FILE: foreach (@ARGV) {
>
>	# get command-line arg or dropped file
>	$inputfile = $_;
>
>	$tempfile = ""; # initialize
>	if ( (length $inputfile) < 26 ) {
>	  $tempfile = "$inputfile.tmp"; # set temp file, if meets test
>	} else {
>	  open (LOG, ">>$session_log");
>	  unless($session_open) {print LOG "\n\n" . scalar localtime() . "
>- -- Unable to create temp file.\n"}

What I found is that if I ran the script directly with hard-coded 
names assigned to @ARGV, it ran fine. Running as a droplet (on the 
same files), it did not. What I discovered is that when file names 
arrive from a droplet they have the full Macintosh file path. This is 
correct behavior, of course, as the file can then be read or written 
successfully. The files don't have to be in the same folder as the 
script.

My solution was to use File::Basename to get the file name only for 
the name length test leaving the value of the file name variable 
along for successful reading/writing. Here's a clipping (with 
embedded comment):

#---
use File::Basename;

# As Mac droplets get full path. Must parse using
# File::Basename method to test file name length. See
# comments at end of script as MacOS has a limit of 31 chars
# in file name.

my ($name,$dir) = fileparse($inputfile); # uses File::Basename method

if ( (length $name) < 26 ) {
     # set temp file, if meets test
     $tempfile = "$inputfile.tmp";
} else {
     # etc...
}
#---

Since no one responded to my initial query and I eventually found the 
solution via testing, I wanted to submit my solution for the list 
archives.

Take care.

Paul
----

P.S. I get plenty of information from the list. I'm hoping this 
assists someone.








==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-anyperl-request@macperl.org