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

[MacPerl] trouble reading a file



Folks,

I'm a novice perl and AppleScripter and reading this list and several perl
books. Lately, I'm testing various clippings from the list, assembling test
scripts. I'm having trouble with one. I hope I'm missing something simple.
I'm using BBEdit to construct scripts and its MacPerl Palette to check
syntax and run the script. (I set the working directory for the palette
prefs to the scripts' directory with no change in results. Running the
script from MacPerl is similar.)

Here's the script:

# -=-=-=-=-
# An AppleScript prompts user for directory. MacPerl works
# with resulting folder path reference string.

my $in_dir = MacPerl::DoAppleScript($show_dialog_in);
$in_dir =~ s/^alias "//;
$in_dir =~ s/"$//;

opendir(DIR, "$in_dir") || die ("Could not open $in_dir\n");
my @files = readdir(DIR);
closedir(DIR);

foreach $file (@files) {
	# do something with each file
	open(FILE, "$file") || die "Could not open $file: $!";

	while (defined($line = <FILE>)) {
	  	print $line;
	}

	close FILE;
}
# -=-=-=-=-

RESULTS:

-=-
# Could not open accesspenn.html: No such file or directory.
File '<AppleEvent>'; Line 77 #[the open (FILE... line]
-=-

If I replace the 'do something with each file' code block with a simple
'print "$file\n";' line, it prints a listing of file names (without full
path ref.) in the selected directory. If I clip the 'do something' code
block and place it in a new file, hard-coding file names or using
AppleScript to prompt the user for a file, it works fine.

Now the file path is fairly long, if that has an impact:

-=-
MacintoshHD:ONLINE:alocalWeb:SyncPJC:PersonalContEd:Scripting:AppleScriptsÄ:curr
ent_work:testdir:accesspenn.html
-=-

Any help would be appreciated.

Paul



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