Chad Kellerman wrote: > ----------------------<snip of code>--------------------------------- > > #!/usr/bin/perl > use strict; > use warnings; > $|++; > > use FileHandle; > > my $msl_Host;
i don't think you need the above line. you are not using it anywhere in your script. you can remove it. the $msl_Host{$host_name} stuff has nothing to do with the above variable. > my %msl_Host; > my $serverList = "/usr/local/account/main-server.list"; > > &mslSplit($serverList); # pass the list into the subroutine. > > foreach my $key (keys %msl_Host) { why not replace the above with: while(my($key,$href) = each %msl_Host){ > my $href = $msl_Host{$key}; > next if ($href->{'ignore_flag'} =~ "#"); the above reg. will sometimes get you in trobule. it works in your case but it will not work all the time. consider: $i = '#abcd'; if($i =~ "^#abcd$"){ #-- syntax error! print "match\n"; } but this will work: if($i =~ m"^#abcd$"){ print "match\n"; } as you have more compliated reg. the "" thingy will get you in trobule. > print "$href->{'host_name'}\n"; > } > > sub mslSplit { > my $msl = new FileHandle "@_", "r" || die $?; > while (<$msl>) { > chomp; > my ($backup_dir, $host_ip, $host_name, $backup_flag,undef) = > split(/\|/) ; > next if $backup_dir =~ /^#directory name/; you can save yourself a few split functions(which is kind of expensive to do) by swapping the order of the split and if like: next if(/^#directory name/); my(...) = split(/\|/); since you only need to split on none commands > my ($comment, undef, $group_dir, $host_dir) = split(/\// , > $backup_dir); > my $daily_server = substr($group_dir,0,length($group_dir)-2); > my %hostEntry = ( > 'backup_dir' => $backup_dir, > 'host_ip' => $host_ip, > 'backup_flag' => $backup_flag, > 'group_dir' => $group_dir, > 'daily_server' => $daily_server, > 'host_dir' => $host_dir, > 'ignore_flag' => $comment, > 'host_name' => $host_name > ); > $msl_Host{$host_name} = \%hostEntry; > } > $msl->close; > } > > -------------------------</end of code>--------------------------------- > This works exactly the way I want it. I can change my print statement > in the foreach loop and print any importatn field that I want. Ther are > no additional fields I need. > > I was wondering what can I do to clean it up. (Maybe be more > efficient) I really don't like having: > > my $msl_Host; > my %msl_Host; i am afraid you can't get away cleanly withtout the my %msl_Host line. david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]