Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Running a script iteratively.

by moklevat (Priest)
on Apr 24, 2008 at 14:22 UTC ( #682636=note: print w/replies, xml ) Need Help??


in reply to Running a script iteratively.

I would use cron for this, but here is a non-robust solution.

Update: For the reasons outlined by Fletch below, don't do this...

#!/usr/bin/perl use strict; use warnings; while(1){ `get_value.pl`; sleep 120; }

Replies are listed 'Best First'.
Re^2: Running a script iteratively.
by Fletch (Chancellor) on Apr 24, 2008 at 14:48 UTC

    Eeeew. Backticks in void context? Use the right tool for the job.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      I said it was non-robust. Perhaps I should have described it as "icky" instead?

        Robustness aside (as it suffers from the same lack of error checking the other proffered version below with system has :), it doesn't express the intent behind the code correctly. Backticks are for capturing the output from an external program; system is for starting an external program who's output you don't care about.

        It's like using map in void context to iterate over a list in place of for; yes it "works", but if the line of code is not building a new list of values from an existing list then you're using the wrong "phrasing" (by which I mean 'not the clearest') to express your intent (map is for expressing transformation, for is for expressing iteration).

        (And I won't go into the "PERL scripts" I've seen that basically consisted of a shebang line and then every line was shell commands in backticks . . . *shudder* :)

        Update: Tweaked for perldoc link somewhere more relevant per prodding from kyle.

        The cake is a lie.
        The cake is a lie.
        The cake is a lie.

      TIMTOWTDI

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://682636]
help
Chatterbox?
[Corion]: Discipulus: I don't know whether I could really do that, but the init process itself mostly launches other processes, and the whole startup is just following a path of dependencies and making sure they are all running. Which basically is what ...
[Discipulus]: when at work my time is (temporarly) owned by the firm, so i do not care (coworkers whatch movies.. I code Perl)
[Corion]: ... make already does, except for files instead of programs. But maybe with some /proc hackery, that could be eliminated and one could use plain make :-D
[choroba]: systemd just makes is asynchronous
[choroba]: so, make -j
[Corion]: Discipulus: Yeah - but when writing Perl to save time (instead of having fun), it helps to look whether you're actually saving time ;) Why spend 5 minutes doing manually what you can spend three years automating? ;)
[Corion]: choroba: Oh, yeah :-D

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2017-07-27 09:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (408 votes). Check out past polls.