Re: Brain stuck on forming a hash

2004-03-19 Thread R. Joseph Newton
Chris Zimmerman wrote:

 Obviously I am a beginner, so bear with me:

 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  UserPass

 I need to generate something like this:

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

Skip this.  Badly written code does not communicate anything.  Dom't use
code-ish symbols and all that garbage until you have the design logic worked
out.



 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?

Expand on this.  Do it in words and sentences, please.  That is the best start
to an effective program.  The sentences can later be easily transformed into
code with minor edits.  What I can gather from the above is:
You have a set of customers.  Don't assume at this point that it will be an
array, though.
For each cutomer, you wish to store data grouped by some sort of filename mask.
What are the files with these masks?
What kind of information do you mean by @restofdata?   This last is crucial, and
should not be passed off cheaply.



 Thanks,
 Chris Zimmerman

I would suggest that you rework your problem description.  You do not, as yet,
have any arrays--they are part of the program you will write.  What do you have,
in existence, to start with?
What do you need to do with it?  Do you want to create an index, maybe?

The two questions above are the crucial ones going into any programming
project.  What do you have to work with, and what do you need as output of the
process?

You will get there much faster if you know where what your destination is.

Joseph


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




Re: Brain stuck on forming a hash

2004-03-19 Thread Chris Zimmerman
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  UserPass

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



Brain stuck on forming a hash

2004-03-18 Thread Chris Zimmerman
Obviously I am a beginner, so bear with me:

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  UserPass

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? 

Thanks,
Chris Zimmerman


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