My contribution showed chop returned the character being chop'ed, not
the explanation below.

Steve


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of $Bill
Luebkert
Sent: Friday, August 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

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

Reply via email to