Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: UNIX shell scripts + pipes

by penguinfuz (Pilgrim)
on May 27, 2002 at 15:50 UTC ( [id://169607]=note: print w/replies, xml ) Need Help??


in reply to UNIX shell scripts + pipes

...i am trying to write a shell script that will run 5 of my programs in sequential order.
Are these programs shell scripts, perl scripts, or what?

...however i don't know how to do it so that the input files can be different
I do not quite understand this one.

...i also want to pipe the out put file so that it can be the input file of the next program.
If the 5 programs are perl scripts why not condence them into 5 subroutines included in the same script? ;) If the programs are shell scripts just feed their output into an array and process by passing each value to another subroutine.

Assuming you are taking output from running the other scripts, here is an example of my understanding.

3 scripts: start.pl, hello.pl, and chopup.pl

start.pl
#! /usr/bin/perl -w use strict; my @program1 = `perl ./hello.pl`; foreach (@program1) { # pass to program2 &program2($_); } sub program2() { # value from program1 my $value = shift; my @newvalue = `echo $value | perl ./chopup.pl`; foreach (@newvalue) { print $_; } }
hello.pl
#! /usr/bin/perl -w use strict; my $message = "Hello Lucy!"; print "$message";
chopup.pl
#! /usr/bin/perl -w use strict; chomp (my $value = <STDIN>); my @value = split "",$value; my $count = @value; my $i; for ($i=0;$i<$count;$i++) { print "\@value[$i] = $value[$i]\n"; }
Run ./start.pl and all files will be processed. I hope this helps, or maybe I should say I hope my understanding is correct! ;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-26 01:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found