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

Re: [MacPerl] UNIX "system" command



At 11:40 -0700 on 970729, JAlexander wrote:
> Does anyone know if there is a MacPerl equivalent of the UNIX "system"
>command?

I don't believe so, no...  The AppleEvents handling might qualify...

> For example, if I wanted to delete a file in UNIX perl, I could type the
> following:
>
> system "rm [filename.filextension]";
>
> How can I replicate this in MacPerl?

The same way you'd do it in UNIX Perl; use `unlink', i.e.
    unlink("foo.fratz");
(See the Blue camel book index under "deleting...files" :-)

Why call system and spawn a new process when you don't have to?  Perl has
almost everything you need built in or available in the libraries.


This brings up an interesting (IMNSHO :-) point I've noticed.  I do much of
my Perl programming on the Mac.  And, until I needed to write programs on
the Mac, I wrote all of my UNIX scripts in shell, awk, sed, ...  That's
what I'd been doing for 10 years and I had no need to change. Then, one
day, I had to do some massive data filtering exercise; it was a choice of
MacPerl or Excel macros. (No contest; the choice took about a picosecond to
make :-)

What drew me to Perl, and to MacPerl in particular, was that none of the
commands I knew and believed I needed were available on my Mac. And it
didn't matter. I use C only when required (and _never_ on the Mac).  I
don't use MPW if I can help it (yes, it reminds me of UNIX, but only enough
to cause frustration :-) I use the MacPerl app, and (Thank you Larry!!)
Perl has one of the greatest built-in toolboxes I've ever seen).

I think the folks who start by writing MacPerl scripts develop a different
way of thinking than those who stay predominately on UNIX systems.  My
spouse sent me a script the other day, nice short script, that contained
the line:
   $cdf = "find $cd -type f -print | sort |";
He thought nothing of it.  I just wouldn't think of embedding this in one
of my scripts; I don't have access to find or sort (or pipes; sigh).  But
that's OK: Perl has find and sort functions that work just fine without
going outside to the shell.  (As a nice side effect, the strictly Perl &
only Perl code is also more portable :-)

I guess I'm wondering about other folks on this list.  Do those of you who
spend most of your time on the Mac find yourselves not even thinking about
things like system() and "open ...|" ?  How many of us work on UNIX and
Mac?  Do the Mac's limitations (I work at Apple; I can call them
limitations :-) affect your Perl coding style?

Vicki

-----------
Vicki Brown, vlb@apple.com  <> Journeyman Sourcerer: Scripts & Philtres
...Toolsmith, Firewarden, Web Gardener, Stagehand, *nixophiliac, JAPH...
Apple Computer: Rhapsody Core OS <> MkLinux: http://www.mklinux.apple.com
      	            ___   UNIX is user-friendly   ___
   (It just isn't promiscuous about which users it is friendly with)



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