Hi, Rather than a dynamic array,you just need to use a correct datastru,a hash. It's maybe better to write codes as below.
[tmp]$ cat groups.txt prod01 456 345 234 prod02 789 517 325 prod03 789 517 325 prod04 789 517 325 prod05 789 517 325 [tmp]$ cat test.pl #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %grouplist; open HD,'groups.txt' or die $!; while(<HD>) { chomp; my @tmp = split; my $groupname = shift @tmp; $grouplist{$groupname} = [EMAIL PROTECTED]; } close HD; print Dumper \%grouplist; __END__ [tmp]$ perl test.pl $VAR1 = { 'prod04' => [ '789', '517', '325' ], 'prod05' => [ '789', '517', '325' ], 'prod01' => [ '456', '345', '234' ], 'prod03' => [ '789', '517', '325' ], 'prod02' => [ '789', '517', '325' ] }; Do you know how to loop through a hash?If not,please write back to the list. 2007/8/23, Justin The Cynical <[EMAIL PROTECTED]>: > Greets. > > I have a 'config file' that contains a group name (alphanumeric) and > machine name/numbers separated by whitespace. Each group is on it's > own line. The file looks like this: > > prod01 456 345 234 > prod02 789 517 325 > ...etc, etc, etc... > > What I am attempting to do is: > Put the file contents into an array > Pull the first entry off the array > Add the name of the array to a 'master array' list of the machine > groups > Then create another array, which would be referenced by the group > name, and contains the machines associated with the group. > > Here is the code I have now that is giving me problems: > > # parse the config file > foreach (@filelist){ > > # for each line of the config file, place the entries > # into a temp array > my @temp=split(/ /); > > # pull the first entry off the array > my $group=shift(@temp); > > # add the name of the array to the main rg array list > push (@grouplist, $group); > > # push the rest of the entries into an array that has > # the same name as the rg in question > foreach (@temp){ > push (@$group, $_); > } > } > > The idea of the script as a whole is to take the config file and split > it into multiple arrays. Once that is done, connect to each machine > and pull some files into another directory. > > The script flow: > -Read the config file, put each line into an array - @temp = qw {prod1 > 456 345 234} > > -Pull the first value from the temp array ($grp) and place it into the > master list - @master = qw {'prod1 prod2} > > -Create a new array on the fly (it needs to be this way as new groups > may be created, or old ones removed) with the name of the pulled value > ($grp) and place the machine names/numbers into that array - @prod1 = > qw {456 345 234} @prod02 = qw {789 517 325} etc... > > -Loop through the master list, using each value as the pointer to the > individual array that contains the machines > > -Connect to each machine in turn and pull the files > > The script runs if I do not use strict (which I consider a Bad > Thing). But when I run it with strict, I receive the following error: > > Can't use string ("prod01") as an ARRAY ref while "strict refs" in use > > Am I missing something really basic that is covered in the Llama (3rd > edition), and can anyone give me any hints? > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > http://learn.perl.org/ > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/