Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Combining perl scripts

by skyraven (Initiate)
on Mar 20, 2006 at 00:17 UTC ( #537838=perlquestion: print w/replies, xml ) Need Help??

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

Hello,

I've just started working with Perl and wanted to ask if there's a functionality for the following:

a) having a perl script compute some values

b) making those values globally reachable in such way so that other perl scripts can use them.

What I want to do:

A. have the output of the iproute package tc -s -d cl sh dev eth0 and eth1 copied in 2 files : stats.down, stats.up

(using a bash crontab rule)
I have already done this.

B. load these 2 files in 2 arrays($down and $up) then:

store in an index array the position in the $down array where each qos class has it's "Sent Bytes" stored.
(this is the same position for $up)

- I have already done this too -

With this data recomputed each 5 minutes I'd like to know if there any possibility for another script(rate.pl) to access the computed $index and the $down, $up arrays from the previous script (without recalculating them).

Then I would just call this second script for each traffic class I have and get the "Sent Bytes" without recomputing everything and eating up resources.

Am I looking for the impossible ? :)

Replies are listed 'Best First'.
Re: Combining perl scripts
by rafl (Friar) on Mar 20, 2006 at 00:31 UTC

    There are a lot of ways to communicate between two perl scripts somehow, but I expect none of them works the way you expect it.

    You can't magically share variables between two unrelated perl interpreters. But you have some other possibilities:

    • Use some way of interprocess communication to exchange the values
      • Write the calculated values somewhere on the disk and read them in the second script
      • Use sockts to communicate
      • Use shared memorie or somesuch
    • Why use seperate scripts for everything? Use one script that does it all
      • Probably seperate the code in modules so you can still have those small scripts doing exactly one task without duplicating code
      • That way it's easily possible to use the results of the first calculation in the later code as you're inside the same perl interpreter and can pass everything around

    Probably not exactly what you were looking for, but I hope it helps.

    Cheers, Flo

      Thanks.

      I'll be looking into the daemon possibility ayrnieu has given me and into the shared memory option you suggested.
Re: Combining perl scripts
by planetscape (Chancellor) on Mar 20, 2006 at 04:28 UTC
Re: Combining perl scripts
by ayrnieu (Beadle) on Mar 20, 2006 at 00:24 UTC

    What do you find infeaseable about writing your calculations to the disk?

      I'm trying to avoid reading those calculations about 2000-4000 times from the disk each 5 minutes.

      I'd be loading them for each IP address graphed in mrtg and I have about 3000 IPs currently in usage.
        I'd suggest that your calculation program act as a daemon, then, and accept requests for information.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2022-05-23 05:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (81 votes). Check out past polls.

    Notices?