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

This script basically queries the SAM database and extracts domain computer accounts:
use strict; use Win32::AdminMisc; use Win32::NetAdmin; my $PDC; my @List; my $file = "C:\\temp\\NODE.txt"; my $Domain = Win32::DomainName(); unless (open (FILE,">$file")) { die $!; } Win32::NetAdmin::GetDomainController("",$Domain,$PDC); if (Win32::AdminMisc::GetMachines($PDC,UF_WORKSTATION_TRUST_ACCOUN +T,\@List,)) { map {print "$_\n"} @List; map {print FILE "$_"."\n"} @List; } close (FILE);
The output also appends the node names with '$'. How can I remove the '$' from the name in the output file? Thanks

Replies are listed 'Best First'.
Re: Remove '$' from system names
by diotalevi (Canon) on Mar 19, 2007 at 00:20 UTC

    The tr/// function can remove your $ characters.

    $\ = "\n"; if ( ... ) { for ( @List ) { tr/$//d; print; print FILE; } }

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Re: Remove '$' from system names
by blogical (Pilgrim) on Mar 18, 2007 at 23:59 UTC
    Please wrap code in <code></code> tags.
Re: Remove '$' from system names
by andye (Curate) on Mar 19, 2007 at 10:41 UTC
    srlowry, if you're confident that every line will have an unwanted character appended to the end of it, you can simply chop it off.

    HTH, andye

    update:

    Looking at your code, it looks like you're using map in a way that's a little unusual. Instead of doing this:

    map {print "$_\n"} @List; map {print FILE "$_"."\n"} @List;

    you might want to consider using foreach instead of map:

    foreach (@List) { chop; print "$_ \n"; print FILE "$_ \n"; }

    best, andye