Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

multi.pl

by premchai21 (Curate)
on Mar 06, 2001 at 21:47 UTC ( #62520=sourcecode: print w/ replies, xml ) Need Help??

Category: Win32 Stuff
Author/Contact Info Drake Wilson (premchai21; drake@libcom.com)
Description: A short script that simply takes a program and runs it with a few different sets of arguments.
#!/usr/bin/perl

my ($sep,$num,@prog,@each);
die "Too few arguments -- for help, try $0 ?\n" if ((@ARGV < 3) && ((@
+ARGV < 1) || ($ARGV[0] !~ /\?|h/)));
$num=shift @ARGV;
print <<MUMBLE if ($num =~ /\?|h/);
Usage: $0 # / p / a /
where # is the number of arguments to take at a time,
      / is any string, used as a separator,
      p is the first part, usually the program name, of each command l
+ine, and
      a is the list of arguments for p.

For example: $0 1 / unzip / foo bar baz /
will execute:
unzip foo
unzip bar
unzip baz

Or: $0 2 / someprog -osz / these are some args /
will execute:
someprog -osz these are
someprog -osz some args
MUMBLE
die "\n" if ($num =~ /\?|h/);
$sep=shift @ARGV;
{
    my $tmp;
    push @prog, $tmp while (($tmp = shift @ARGV) && $tmp ne $sep);
    push @each, $tmp while (($tmp = shift @ARGV) && $tmp ne $sep);
}
while (@each)
{
    my @here;
    foreach (1..$num) { push @here, shift @each; }
    system(@prog,@here);
}

Comment on multi.pl
Download Code
Replies are listed 'Best First'.
Re: multi.pl
by merlyn (Sage) on Mar 06, 2001 at 21:59 UTC
      merlyn, are you running a popularity test with your links? :)
        Nope. I wanna see if what I'm saying is useful to people. And one way to do that more-or-less transparently is to know how many people clicked on a link, which my /cgi/go framework will tell me.

        Of course, it's been a long time since that URL actually fired off a separate process on my server: it's now a nice mod_perl handler very early in the Trans phase, but the URL is mnemonic enough that I stayed with it. {grin}

        For more details on what /cgi/go is and how to code it, see my WT column where I introduced it to my site.

        -- Randal L. Schwartz, Perl hacker

      Well what do you know -- there's a Perl version.

      And I thought xargs was only a Unix thing...

Back to Code Catacombs

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2015-08-01 00:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (285 votes), past polls