i figure if i'm going to be a nut for efficiency might as well see it 
split is ok with null....


  my @fldrs = split /\00/, $regval;
  foreach $regval (@fldrs){
    if(-f $regval){
      &rep("Found file $regval|<-",$verb);
      push @watch, $regval;
    }elsif(-d $regval){
      &rep("Found directory $regval|<-",$verb);
      push @watch, $regval;
    }else{ &rep("How did this get in here? val is: $regval|<-", $verb); }
  }

then i don't need to use the match to catch the files/directories and 
there's even an error check in the run... cuts the block down 
tremendously, and the split takes care of both null removal and splitting 
it up to get the files/directories at once....is PERL one of the languages 
where the build in functions like split are optimized over pattern 
matches?

=o)




"$Bill Luebkert" <[EMAIL PROTECTED]> 
08/19/2005 12:01 PM

To
[EMAIL PROTECTED]
cc
[email protected]
Subject
Re: trouble cleaning a registry pull (solution!)






Steve Sarapata wrote:

> Incase people are interested....
> 
> chomp wasn't working since it removes new-lines (was my first thought)
> chop worked but i couldn't verify i wasn't taking off too much
> 
> someone here has a byte dumping program in hex. he asked that i log the 
> ending character.  after doing so he ran it through the program it turns
> 
> out the registry separates values using the NULL character. 
> 
> the problem I found with this is that it ONLY works in a m// or s/// 
> context when it is the LONE item in the part to be matched (that or the 
> s/// context will work if i spend more time with it)
> 
> the solution I found was to change the chunk of code sent last time to:

This is just plain silly - it's a simple problem that is easily solved 
with
a simple RE.  Check this test code out:

use strict;
use warnings;

# create a var with some trailing WS and nulls

my $regval = "fubar  \000\000  \000\000";

dumpit $regval;                          # do a hexdump of $regval

# your code:

while (my $q = chop $regval) {
                 unless ($q =~ m/\0/) {
                                 $regval .= $q;
                                 last;
                 }
}

dumpit $regval;

# your code will chop till it finds a non-null and then put it back on.

# this code will just remove any nulls and whitespace from the end with
a single stmt. :

$regval = "fubar  \000\000  \000\000";

dumpit $regval;

$regval =~ s/[\s\000]+$//;               # remove any trailing WS or nulls

dumpit $regval;

__END__

Here are the 4 dumpit's from above code:

0000  66 75 62 61 72 20 20 00  00 20 20 00 00            fubar  ..  ..
0000  66 75 62 61 72 20 20 00  00 20 20                  fubar  ..
0000  66 75 62 61 72 20 20 00  00 20 20 00 00            fubar  ..  ..
0000  66 75 62 61 72                                     fubar

The last line is the only one that shows a good result (admittedly to
a slightly different but broader scenario).

> i dont know how many will find this usable news, but i figure it cannot 
> hurt to inform the list the solution that I found


-- 
  ,-/-  __      _  _         $Bill Luebkert    Mailto:[EMAIL PROTECTED]
 (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      Castle of Medieval Myth & Magic 
http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)


_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to