[EMAIL PROTECTED] wrote:
> I had some help to get a portion of something I'm working on
> working but I still don't understand what's going on and was
> hoping someone out there could explain. Until I understand I
> wont really be able to use the package.
>
> this code works to get the "array" as a space separated list (code
> between *********************************)
>
> *********************************
> #! /usr/bin/perl -w
> # use strict;
> use Getopt::Long; # used in getting unix-style options use
> Win32::TieRegistry;
>
> my( @watch, @vals);
> my($posix, $file, $key, $val, $reg, $iter, $done); my($help,
> $verb, $qrev, $rev, $revdat, $modules); # standard
> options/revision information variables $posix=0; $iter=0;
> $done=0; $modules="\tnothing as of now\n\n"; $help=0;
> $qrev=0; $rev="0.0"; $revdat="08/15/2005"; $verb=0;
>
> ###########################
> # this section deals with options. it looks for posix-style
> options passed. that is, <script> -option [value] # now get
> the options GetOptions ('help' => \$help, 'verbose+' =>
> \$verb, 'version+' => \$qrev, 'posix' => \$posix,
> 'iterations:i' =>\$iter);
>
> ######
> # arguments ARE required
> # if help or version is not on OR BOTH of the next two and
> ONE of the last two, we have no arguments unless($help || $iter>0){
> print "\nYou must supply at least 1 parameter(s) to run
> this program. It
> needs: iterations (must be positive, non-zero number\n"; print
> "Turning on help.\n"; $help++;
> }
>
> #
> # now put the options to use...
> #
> if($help){ # show options and use since asked for
> print "\tFile: $0\tVersion: $rev\tReleased: $revdat\n";
> print "\nThis is the $0 file.\n";
> print "\nThe options for this file are:\n";
> print "\t-help\t\tThis help screen only (overrides all other
> options)\n"; print "\t-version\tList Version and exit (overrides
> everything but -help)\n"; print "\t-verbose\tTurn on verbose
> (useful for debugging
> errors; call
> twice\n\t\t\tfor extra output)\n";
> # print "\t-\t\t\n";
> print "\t-iterations\t\thow many times shall it modify files?\n";
> # print "\t-posix\t\tflag it for posix system\n";
> print "\n\tusage ([] denotes optional argument {} denotes
> default value
> {} denotes\n\t\t option set of which your choice of one is
> required):\n"; print "$0 [-help] [-version] [-verbose]\n\n";
> print "to debug try: $0 -verb -verb > debug_log.txt\n\n";
>
> if($verb){
>
> }
>
> exit; # leave the script since we were just showing use }
>
> if($qrev){ # query for versions being used
> print "\tFile: $0\tVersion: $rev\tReleased: $revdat\n"; exit; #
> ONLY print versions }
>
>
>
> ############
> # this section finds the registry key value for what is watched.
> # first it queries the registry for them, then it imports them
> # into an array. while it does this it drops the c:\windows\ # dirs
> for boot protection.
>
> # we need the Win32::TieRegistry
> # module. via this module we get two items from the registry and
> # then check them for files that we can modify that are not in a
> # place that makes them sensitive to booting right (services)
> # then place the values that are files into an array (@watch)
> # which will be used later to test SeaNotify
>
> # use Win32::TieRegistry (TiedHash => '\%reg', Delimiter => "/");
>
> $key = $Registry -> Delimiter("/");
>
> $key = $Registry ->
> {"HKEY_LOCAL_MACHINE/System/CurrentControlSet/Services/SeaNoti
> fy/"} ->
> MemberNames;
> @vals = $Registry ->
> {"HKEY_LOCAL_MACHINE/System/CurrentControlSet/Services/SeaNoti
> fy/"} ->
> GetValue("SeaNotifyFiles");
>
> foreach $val (@vals){
> if(-f $val){ push @watch,$val; }
>
> }
>
> ####################################
> #----------------------------------#
> # temporary to test correct access #
> # method to registry #
> #----------------------------------#
> ####################################
> foreach $val (@watch){
> print STDOUT "found value $val in resigtry\n";
> }
>
> *********************************
>
> yet this code does not run, but rather errs on the call to membername
> (again, in the *********************************)
>
> *********************************
>
> #! /usr/bin/perl -w
> use strict;
> use Getopt::Long; # used in getting unix-style options
> use Win32::TieRegistry (TiedHash => '\%reg', Delimiter => "/");
> use POSIX;
> use File::Copy "mv";
>
> my(%reg, $reg, @watch, @vals);
> my($posix, $file, $key, $val, $iter, $done);
> my($help, $verb, $qrev, $rev, $revdat, $modules); # standard
> options/revision information variables
> $posix=0; $iter=0; $done=0;
> $modules="\tnothing as of now\n\n"; $help=0; $qrev=0;
> $rev="0.0"; $revdat="08/15/2005"; $verb=0;
>
> ###########################
> # this section deals with options. it looks for posix-style options
> passed. that is, <script> -option [value]
> # now get the options
> GetOptions ('help' => \$help, 'verbose+' => \$verb, 'version+' =>
> \$qrev, 'posix' => \$posix, 'iterations:i' =>\$iter);
>
> ######
> # arguments ARE required
> # if help or version is not on OR BOTH of the next two and
> ONE of the last
> two, we have no arguments
> unless($help || $iter>0){
> print "\nYou must supply at least 1 parameter(s) to run
> this program. It
> needs: iterations (must be positive, non-zero number\n"; print
> "Turning on help.\n"; $help++;
> }
>
> #
> # now put the options to use...
> #
> if($help){ # show options and use since asked for
> print "\tFile: $0\tVersion: $rev\tReleased: $revdat\n";
> print "\nThis is the $0 file.\n";
> print "\nThe options for this file are:\n";
> print "\t-help\t\tThis help screen only (overrides all other
> options)\n"; print "\t-version\tList Version and exit (overrides
> everything but -help)\n"; print "\t-verbose\tTurn on verbose
> (useful for debugging
> errors; call
> twice\n\t\t\tfor extra output)\n";
> # print "\t-\t\t\n";
> print "\t-iterations\t\thow many times shall it modify files?\n";
> # print "\t-posix\t\tflag it for posix system\n";
> print "\n\tusage ([] denotes optional argument {} denotes
> default value
> {} denotes\n\t\t option set of which your choice of one is
> required):\n"; print "$0 [-help] [-version] [-verbose]\n\n";
> print "to debug try: $0 -verb -verb > debug_log.txt\n\n";
>
> if($verb){
>
> }
>
> exit; # leave the script since we were just showing use }
>
> if($qrev){ # query for versions being used
> print "\tFile: $0\tVersion: $rev\tReleased: $revdat\n"; exit; #
> ONLY print versions }
>
> ############
> # this section finds the registry key value for what is watched.
> # first it queries the registry for them, then it imports them
> # into an array. while it does this it drops the c:\windows\ dirs #
> for boot protection.
>
> # we're doing the windows version, we need the Win32::TieRegistry
> # module via this module we get two items from the registry and
> # then check them for files that we can modify that are not in a
> # place that makes them sensitive to booting right (services)
> # then place the values that are files into an array (@watch)
> # which will be used later to test SeaNotify
>
> # declaration of TieReg @ beginning: use Win32::TieRegistry
> (TiedHash => '\%reg', Delimiter => "/");
>
> $key = $reg ->
> {"HKEY_LOCAL_MACHINE/System/CurrentControlSet/Services/SeaNoti
> fy/"} ->
> MemberNames;
> @vals = $reg ->
> {"HKEY_LOCAL_MACHINE/System/CurrentControlSet/Services/SeaNoti
> fy/"} ->
> GetValue("/SeaNotifyFiles");
>
> foreach $val (@vals){
> if(-f $val){ push @watch,$val; }
>
>
> ####################################
> #----------------------------------#
> # temporary to test correct access #
> # method to registry #
> #----------------------------------#
> ####################################
> foreach $val (@watch){
> print STDOUT "found value $val in resigtry\n";
> }
>
> *********************************
>
> The latter set is what I initially wrote to do this,
> Thank you in advance for any time taken to help me understand
> what the
> differences are that allow the first one to work.
The first problem is with the code you posted. Most of the code seems to
be unrelated to your problem, and is therefore so much clutter.
Secondly, it has been mauled by something. Lines arbritrarily
concatenated and wrapped, resulting in code that won't even compile
without editing, and probaly made worse by my quoting. It would have
been better to provide small examples, using registry keys that are
likely to exist on most machines, that can be simply cut and pasted, and
then run. The easier it is for somebody to just run the code you are
having problems with, the easier it is to help you.
So, not being able to easily run the provided code (or read it), you
primary problem may be related to the TiedHash in the constructor call.
According to the documentation, it should either be "TiedHash =>
'%RegHash'" or "TiedHash => \%RegHash" (after first declaring %RegHash),
not "TiedHash => '\%reg'" as you have.
Also, according to the documentation, MemberNames returns an array, not
a scalar as your code seems to expect. In fact, I couldn't see where the
results of the call to MemberNames was used. And, GetValue doesn't
return an an array of values as you seem to expect.
A couple of general comments. "use warnings" is preferred to "-w",
unless you are using a really old version of Perl. Also, try to declare
variables in the smallest possible scope. Avoid global variables.
HTH
-----------------------------------------------------------------------
The information contained in this e-mail is confidential and solely
for the intended addressee(s). Unauthorised reproduction, disclosure,
modification, and/or distribution of this email may be unlawful. If you
have received this email in error, please notify the sender immediately
and delete it from your system. The views expressed in this message
do not necessarily reflect those of LIFFE Holdings Plc or any of its subsidiary
companies.
-----------------------------------------------------------------------
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs