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

Re: [MacPerl] Too many arguments?



Steve Swantz requested:

>Obvious to you, but I'm a glob virgin who's still using readdir. It'll be
>obvious to me, too, after you show me a fragment! :-)

Well, readdir would actually work as well (or better).

I have illustrated the three approaches in the code snippet below.  To test
the three approaches, I just cut and pasted each version to the top of the
code and resaved.

Finally, as Peter Hartmann just posted:

"I could solve this problem by increasing the memory partition of the applet
 in the Finder:"

<BLUSH> He's correct.  I think I have even done this, but forgot :-( </BLUSH>

Finally, one more choice is illustrated in the snippet.  Using readdir, you
can retrieve just one file at a time from the directory, and in this case
it seems to me you ought to be able to process any number of files without
running out of memory.

-David-

---=== CUT ===---
#!perl
#
# usingGlob.pl

# Get the name of what was dropped
$folder   = shift(@ARGV);

# Is it a folder?
@filetype = MacPerl::GetFileInfo($folder);
if($#filetype >= 0) { die "How to use: Drag a folder onto this program.\n";
}    chdir $folder;

# Get contents of the folder
chdir $folder;
@files = glob "*";

foreach $file (@files) { print "$folder:$file\n"; }

__END__

#!perl
#
# using_readdir.pl

# Get the name of what was dropped
$folder   = shift(@ARGV);

# Is it a folder?
@filetype = MacPerl::GetFileInfo($folder);
if($#filetype >= 0) { die "How to use: Drag a folder onto this program.\n"; }

chdir $folder;

# Get contents of the folder
opendir(DIR, $folder) or die "Programming bug: please see programmer: $!\n";;
@files = readdir(DIR);
closedir(DIR);

foreach $file (@files) { print "$folder:$file\n"; }

__END__

#!perl
#
# using1readdir.pl
# (retrieving file names one at a time)

# Get the name of what was dropped
$folder   = shift(@ARGV);

# Is it a folder?
@filetype = MacPerl::GetFileInfo($folder);
if($#filetype >= 0) { die "How to use: Drag a folder onto this program.\n"; }

# Get contents of the folder
opendir(DIR, $folder) or die "Programming bug: please see programmer: $!\n";;
foreach $file (readdir DIR) { print "$folder:$file\n"; }
closedir(DIR);

__END__

#!perl
#
# usingFiles.pl

# Get the name of what was dropped
@files = @ARGV;

foreach $file (@files) { print "$file\n"; }

__END__
---=== END CUT ===---

David Steffen, Ph.D.
President, Biomedical Computing, Inc. <http://www.biomedcomp.com/>
Phone: (713) 610-9770 FAX: (713) 610-9769 E-mail: steffen@biomedcomp.com



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch