RayRay459 has asked for the wisdom of the Perl Monks concerning the following question:

Can anyone tell me why this is only chop'ing the last server on the list instead of every server on the list. when i open up the text file that the output is piped to, it shows a $ at the end of the server name EXCEPT FOR THE LAST SERVER and i can't get it to go away on every server in the list. Please help. Ray
# Ray Espinoza # GetDomainServers.pl # Get servers in domain and matches # sends the output to a text file. ################################################################ #!D:\Perl\bin -w use strict; use Win32::NetAdmin; open (OUT,">list.txt") || die "Cannot create machine list. :$!"; # This will get the list of machine names from the PDC my @users; Win32::NetAdmin::GetUsers("\\\\PDC",'',\@users); my @computers = grep { /\$$/ } @users; @computers = join("\n",@computers); foreach my $box (@computers) { chop $box; # removes terminal char, must be $ from grep print OUT "$box\n"; # print each $box on a newline } close OUT;

Replies are listed 'Best First'.
Re: same question...different results..:o)
by rchiav (Deacon) on Aug 08, 2001 at 03:09 UTC
    @computers = join("\n",@computers); what do you think this line is doing? What you've done is join all the array elements of @computers and put them into one element. So when you chop, you've got all the things that used to be in the array as one string.

    Rich

      DOH! thanks for your help rich. now on to figuring out how to get the ip addresses of the servers in my list. Ray
Re: same question...different results..:o)
by VSarkiss (Monsignor) on Aug 08, 2001 at 03:13 UTC

    Well, tachyon gave you the answer that worked, so I really should butt out and let him answer. Nonetheless....

    This line of code: @computers = join("\n",@computers);is creating a single array element with everything glued together (including the funky $). I'm not sure what its purpose is in your code, since you then try to traverse the array in the foreach loop that follows. You should either leave out that statement, or use it after you've chopped off the $.

    HTH