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

[MacPerl] Use of open, close, and MacPerl::SetFileInfo



-----BEGIN PGP SIGNED MESSAGE-----

Here's a little snippet from some code of mine which works fine
every time... only I haven't tested it on my trusty Linux box yet
:-)

| close INDEXFILE;
| if ($OSNAME eq "MacOS")
| {
|     MacPerl::SetFileInfo("R*ch", "TEXT",$index_file);
| };
|
| # Some more code here...
|
| open INDEXFILE, ">" . $index_file;

Which, for the purpose, could probably be written:

| if ($OSNAME eq "MacOS")
| {
|     close INDEXFILE;
|     MacPerl::SetFileInfo("R*ch", "TEXT",$index_file);
|     open INDEXFILE, ">" . $index_file;
| };
|
| # Some more code here...

I read this whole thing as "I want to create this file. Now, if I'm
running on a Macintosh, I would like to set the file type. Once
that's done, I want to start writing to the file..."

This way, I don't worry (or care) about whether the file is "really"
created just after the "open" or the "close". I create the file,
then work with it. "Working with it" on the Mac also happens to
include doing stuff with the Finder database, such as setting file
type and creator.

If you're really worried about the performance hit of the
open/close/setinfo/open cycle, don't worry about setting the file
info until AFTER you've finished writing to the file. After all,
it's not really much use letting people double-click it until
there's something worth looking at :-)

If something else is trying to read from the file at the same time
that you're writing to it, perhaps you should be looking at a pipe
or inter-process communication? On the Mac you have Apple Events or
TCP/IP, on Unix you have pipes, STDIN/STDOUT, TCP/IP, Sys V IPC,
blah blah blah.

I haven't explored that field yet - but it looks interesting enough
to warrant a play sometime this month.

- -Alex Satrapa
Newbie PERL/MacPerl programmer
-----BEGIN PGP SIGNATURE-----
Version: 2.6.2, by FileCrypt 1.0

iQCVAwUBM7sHPWFCmlEesL8FAQFdYAQAiakFSARQdX/VmYEjh3ZpbykYTQcExXWA
Wf1uPHNd4a4hbaUoJ5YF/FwCeEestKtcxeQ1E63GVM3IAqc3mK5P/VNCQSfOEJkq
dCqSFIE5vTxb6AS399t85QC2YPlzqJCWTf1PIPyGPkQCdfpK+XDlUqwW9mDqOlr+
GtPL/JWzxTA=
=8iWi
-----END PGP SIGNATURE-----

finger packrat@ucnet.canberra.edu.au for pgp public key.



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