I'm writing a script which will:
1. Generate arguments to be passed to another program.
2. Run the second program with arguments.
3. Write the output to the current directory.
Here is an example of the input to the script:
cat1-dd1 as boston1-nta1 peer 10
dog1-dd1 as philly-snta1 peer 10
bird-dd1 as philly-snta1 peer 10
fish-dd1 as boston1-nta1 peer 10
Heres the code:
#!/usr/local/bin/perl -w
use strict;
my $config = $ARGV[0];
my $date = $ARGV[1];
my $program = "animals";
my $matrix = "netmatrix";
my $path = "path";
my %hash;
my $host;
my $key;
die "Usage: $0 path-to-config-file yyyymmdd\n" unless @ARGV == 2;
open (CONFIG, $config) || die "Cannot open $config_file:$!\n";
while (my $line = <CONFIG>) {
chomp $line;
next if ($line =~ /^\#/);
my ($router, $cache, $nta, $as, $Sample) = split (' ', $line);
$host = (split "-", $nta)[0];
$host =~ tr/0-9//d;
$hash{$router}=$host;
}
foreach $key (keys %hash) {
print "$program $hash{$key} $matrix $path/CISCO_$key.clean";
####I'll execute the program here, once this is figured out
}
Which produces the following output:
animals boston netmatrix path/CISCO_fish-dd1.clean
animals philly netmatrix path/CISCO_dog1-dd1.clean
animals philly netmatrix path/CISCO_bird-dd1.clean
animals boston netmatrix path/CISCO_cat1-dd1.clean
What I want to do is test for the existence a duplicate key value, and if so, append
$path/CISCO_$key.clean to the end of the statement:
animals philly netmatrix path/CISCO_dog1-dd1.clean path/CISCO_bird-dd1.clean
animals boston netmatrix path/CISCO_fish-dd1.clean path/CISCO_cat1-dd1.clean
Can anyone help out?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.