in reply to Passing Data Between Perl Programs

G'day jmmitc06,

Is this the type of thing you had in mind?

"program 1 generates a variable '$number'"

$ cat var_gen.pl #!/usr/bin/env perl while (<>) { chomp; my $number = length; print "$number\n"; }

"program 2 would print $number"

$ cat var_out.pl #!/usr/bin/env perl while (<>) { print "Got $_" }

Sample run (var_gen.pl reads user input from which it generates a number which it passes to var_out.pl where the number is included in an output message):

$ var_gen.pl | var_out.pl 1 12 123 1234 12345 Got 1 Got 2 Got 3 Got 4 Got 5

-- Ken

Replies are listed 'Best First'.
Re^2: Passing Data Between Perl Programs
by jmmitc06 (Beadle) on Jul 05, 2013 at 05:00 UTC

    Not exactly but thanks, I know about piping I'm wanting to have two programs running concurrently, program 1 generating data and passing it to the already running program 2 where something is done to it. The inter process communication module mentioned above does what I was looking for. Thanks though

      If it's a linear feed, you can probably use a FIFO pipe (assuming Unix, I don't know how easy it is on Windows). man mkfifo. Basically it's a file that exists purely as a place for ... well, once process to feed into and another to read out of. You use it by (once making it) by simply having one process open it for writing, and the other for reading.

        Thanks for the reply and sorry it took so long to respond, very busy at work. Yeah, I'm in unix and I used your approach and got it working in some test programs. It appears to do what I need and is a good alternative to IPC modules.