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

Hi folks, I'm a little stuck with something and hope you could help me. I am working on a program that looks up WINS information from W2K registry and assigns it to $test variable. Then I want to split it into two variables but can't get it working.

In this case for eg.. "47.56.1.1 47.57.2.2" would be read and assigned to $test variable from the registry.

--- snip ----
$test = "$RemoteSystem{'NetBios'}{$nic_service}{NameServerlist}";
($a, $b) = split(/ +/, $test);
print "$a -- $b\n";
-------------

This doesn't work, but if I manually assign $test = "47.56.1.1 47.57.2.2"; then it works.
Any help would be appriciated,
Thanks

Replies are listed 'Best First'.
Re: Splitting strings
by thelenm (Vicar) on Apr 08, 2002 at 22:08 UTC
    It's hard to tell what might be going wrong with such a small snippet of code... what is in $test before you do the splitting?
      In this case I am reading WINS address from registry. Problem is that in the w2k registry, both primary and secondary wins address is in one string. I want to split it into two variables and then compare agains other ip addresses.
        I verified that $test has proper data assigned by inserting a print statement.
        --- snip ----
        $test = "$RemoteSystem{'NetBios'}{$nic_service}{NameServerlist}";
        print "$test\n"; #this shows me that $test has proper string assigned
        ($a, $b) = split(/ +/, $test);
        print "$a -- $b\n";
        -------------
Re: Splitting strings
by Cody Pendant (Prior) on Apr 09, 2002 at 05:39 UTC
    Maybe I'm confused, but it looks to me as if you're trying to split a string where there's one or more whitespaces.

    Your manually-inserted example has a space, though it's hard to see.

    It's 47.56.1.1[space]47.57.2.2 right?

    I don't know what $RemoteSystem{'NetBios'}{$nic_service}{NameServerlist} puts into $test, but I don't see any spaces there.
    --

    ($_='jjjuuusssttt annootthhrer pppeeerrrlll haaaccckkeer')=~y/a-z//s;print;