Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Problem with MacPerl

by gambler (Initiate)
on Feb 14, 2001 at 20:24 UTC ( [id://58374]=perlquestion: print w/replies, xml ) Need Help??

gambler has asked for the wisdom of the Perl Monks concerning the following question:

Good morning fellow monks:) I have a problem with a script I wrote that is being installed on a Mac (OS 8.6 I think). The script runs fine but has to run continuously. The script parses information from 2 files that are FTPed to the server every half hour. It then sends the information to a .js file for use on a webpage. I originally developed the script to produce the page (worked great, only ran when page called) but the company has to be able to edit the page in a program called GoLive?? which won't open the file. I am currently using sleep() and this causes the problem because the Mac doesn't seem to multi-task very well. i.e. if you have another script to run it doesn't! Does anybody have a work around or a way to call the script from the HTML page? Thanks, gang!

Replies are listed 'Best First'.
Re: Problem with MacPerl
by Trimbach (Curate) on Feb 14, 2001 at 23:19 UTC
    Instead of "sleeping" your program you should look into one of the cron-type programs available for Macintosh. One of them is the commercial MacAT another is the shareware Chronograph Or, since your problem is so well defined, you might be able to just whip up some Applescript that'll do it for you.

    Of course, when OS X comes out next month, you'll have access to real cron and preemptive multitasking and this won't be a problem at all. :-D

    Gary Blackburn
    Trained Killer

Re: Problem with MacPerl
by CiceroLove (Monk) on Feb 15, 2001 at 00:20 UTC
    I'm come from a long line of Mac lovers. (I'm looking at my PowerBook G3 running my mail server right now). MacPerl is in my opinion a dastardly half-migration of Perl per se. Things like sleep and @readinlines = <DATAFILE>; do not work as expected if you are coming from a *NIX environment. I am sad to say that sleep is just as dastardly in AppleScript. (as a side note, sleep is also a crappy command in AppleScript but is supposed to be changed in OSX). The reason why sleep does not work is that it cannot break the "command cycle". That si to say it must wait until an empty moment to be run. But it's sleeping so the OS just skips right over its request, the script wakes up because the OS "touched" it and then waits until the OS comes around again. But by that time it's already asleep again! This is obviously not the intended behaviour. An Apple Engineer explained to me at MacWorld that the best thing to do is give it a task that must be waited upon by the OS, so that the suggestion above to do selects and stuff is probably your best short term bet. In that way, you can be doing something in the background that would require the OS to leave and come back to give processor time you would have a better chance of getting your script to run. Or using an extension (I can't remember the name of some right now but you can find them on versiontracker.com) because extensions live in the processor cycle. I know htis is long but one last thing. There is a Scripting Addition that does true mutli-tasking that you could use with Appelscript to create a similar "sleep" behaviour. You can email me at gregs@l90.com is you want more info. HTH CiceroLove
      Just to add to the previous node, you can use Scripting Additions directly from MacPerl using the Mac::Glue module if you want to go that route.

      ----
      Coyote

      @array = <FILE> works exactly the same as on Unix. It is just entirely false to say otherwise.

      And sleep() works as intended. OK, so it can't just begin sleeping right away if something else is happening; welcome to cooperative multitasking! To blame MacPerl for the Mac OS architecture is pretty silly.

      One may also wish to look into Mac::Events::WaitNextEvent() for some purposes.

(Coyote) Re: Problem with MacPerl
by Coyote (Deacon) on Feb 15, 2001 at 00:14 UTC
    You can get around the multitasking problem on the Mac by running multiple instances of the interpreter by creating runtime versions of your scripts. You can do this from the MacPerl save dialog. I have had success with this approach in the past with some long running data crunching scripts. If I understand the process correctly, creating a runtime version makes a copy of the MacPerl executable and adds your script and required modules to the resource fork of the MacPerl copy, so this can eat up quite a bit of diskspace. I would recommend creating a runtime version of your script and using one of the schedulers that Trimbach mentioned in an earlier node.

    Hope this helps.

    ----
    Coyote

Re: Problem with MacPerl
by kschwab (Vicar) on Feb 14, 2001 at 20:45 UTC
    I know nothing about Macs, but perhaps replacing sleep() calls with something like:
    sub mysleep { select(undef,undef,undef,$_[0]); }
    would change the underlying call to something friendlier to the cooperative multitasking ?
Re: Problem with MacPerl
by raster (Novice) on Feb 15, 2001 at 03:20 UTC
    I'd do one of two things, use a scheduler (I like T-Minus Ten, but there are other cron-like apps for the Mac) or if that's no good, you can have an AppleScript that remains open, sleeping most of the time, and running the script every x amount of minutes. You might try the MacPerl list or archives for more specifics, or helpful individuals - http://www.macperl.org/
Re: Problem with MacPerl
by gambler (Initiate) on Feb 15, 2001 at 05:21 UTC
    Just wanted to thank all those that replied! I think I will try out a couple of the schedulers mentioned tommorow-I'll let you know how it goes. Thanks again,gambler

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://58374]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-26 02:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found