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

I want to put some registry subkeys into array @Print_Printer, but I can't get it to work. I am using both Win32::TieRegistry and grep for the first time this week. Please be gentle. I don't know why the TieRegistry documentation "Listing all subkeys and values" example uses m#^/# for it's grep search criteria. Here is an example that I'm playing with on Windows XP and Windows NT4:

use strict; use Win32::TieRegistry ( Delimiter=>"/" ); $Registry->Delimiter("/"); my (@Print_Printer) = (); my ($sysKey, $Print_Printer); @Print_Printer = grep( m#^/#, keys( %{$sysKey->{"LMachine/SYSTEM/Curre +ntControlSet/Control/Print/Printers/"}} ) ); foreach $Print_Printer(@Print_Printer){ print "$Print_Printer\n"; }

Replies are listed 'Best First'.
Re: TieRegistry Listing All Subkeys with Grep
by benn (Vicar) on Jul 26, 2003 at 12:28 UTC
    If you look closely at $sysKey, you'll see that it never gets set to anything. I think you wanted something like this... (tested, would you believe!)
    [first 3 lines as per your code] my $sysKey = $Registry->{"LMachine/SYSTEM/CurrentControlSet/Control/Pr +int/Printers/"} ; my @Print_Printer = grep( m#^/#, keys %$sysKey); [last 3 lines as per your code]
    As to the grep/regex, it only 'lets through' keys that start with '/'. The keys of $sysKey start off as (on my machine) as... CAPTURE FAX BVRP/, Capture fax BVRP Extended/, Speedway!fax/, Brother HL-1250 series/, /, /StartOnBoot,/PrintersMask/ after the grep, we're left with...
    /StartOnBoot /PrintersMask
    ...which is presumably what you were looking for.

    HTH, Ben.