My apologies to the list for being so vague in the first message. My on-call week has sapped what little brain power i had left. Here's what I was able to come up with yesterday:

sub read_cust_config {
my ($direction)=$_[0];
foreach $cust (@customers) {
chomp $cust;
$configfile="$path/config/$cust.$direction.cfg";
open(CONFIG,$configfile) || warn "Cannot open file for $cust! $!\n";
while ($line=<CONFIG>)
{
if ($line =~ /^#+\s*/) {next};
chomp $line;
($mask,@data)=split (/\s+/,$line);
foreach (@data) {
[EMAIL PROTECTED];
}
}
close (CONFIG);
}
}



zentara wrote:


On Thu, 18 Mar 2004 10:43:07 -0600, [EMAIL PROTECTED] (Chris
Zimmerman) wrote:



Obviously I am a beginner, so bear with me:



It's good practice for everyone :-)




I have an array, @customers, that has a list of names. For each customer I need to read in a config file, $cust.morestuff.cfg which is formatted:

Filename-mask Upload Name Hostname X-Type User Pass


I need to generate something like this:


$customer->$mask->@restofdata
                ->$mask->@restofdata

Each customer will have multiple filemasks (basically the beginning couple of letters of the filename so I do not have to match exact files-some contain date names) with their appropriate processing information. I need to know the best way to get this together. Clear as mud?


The script below gives good output for files:


c,joe,joepass,joehost
a,bill,billpass,billhost
b,bob,bobpass,bobhost

--- #YAML:1.0
bill:
 Xtype: a
 hostname: billhost
 pass: billpass
 user: bill
bob:
 Xtype: b
 hostname: bobhost
 pass: bobpass
 user: bob
joe:
 Xtype: c
 hostname: joehost
 pass: joepass
 user: joe

###############################################
#!/usr/bin/perl
use warnings;
use strict;
use YAML;

my @custdata = ('joe', 'bill', 'bob');

my %customers;

foreach my $cust(@custdata){
open(CD,"<$cust-moredata.cfg") or warn "Can't open $!";
while (<CD>){
my ($Xtype,$user,$pass,$hostname)= split ' ',$_; print "$Xtype,$user,$pass,$hostname\n";
$customers{$cust}{'user'} = $user;
$customers{$cust}{'Xtype'} = $Xtype;
$customers{$cust}{'pass'} = $pass;
$customers{$cust}{'hostname'} = $hostname;
} close CD
}
print Dump(\%customers);
__END__
####################################################
And the moredata files


#joe-moredata.cfg
c   joe   joepass   joehost

#bill-moredata.cfg
a   bill   billpass   billhost

#bob-moredata.cfg
b   bob   bobpass   bobhost








-- I'm not really a human, but I play one on earth. http://zentara.net/japh.html





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to