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

Hi monks! I'm writing a script that uses snmpget to retrieve values via MIBs. One of my return values comes back as: "String: "00.55.55.00"" (without the outer quotes of course). I then proceed to strip the unnecessary characters with:
$dsfe_mask =~ s/\n|STRING: //g; $dsfe_mask =~ s/"+//g; $dsfe_mask =~ s/\D+//g;
this leaves me with the value 00555500. I need to split all these characters/numbers into seperate variables or into a list. I tried doing:  @list = split(//,$dsfe_mask); but it doesn't work... Is there a way to do this? This value is a hexadecimal mask that will eventually tell me which test cases I need to be testing for (thats an over simplification but I don't think you need to know exactly what I'm doing to be able to help me)

Replies are listed 'Best First'.
Re: split number into seperate numbers and store in an array or seperate variables
by dharanivasan (Scribe) on Dec 18, 2008 at 06:22 UTC
Re: split number into seperate numbers and store in an array or seperate variables
by ccn (Vicar) on Dec 17, 2008 at 22:33 UTC
    my $dsfe = 'String: "00.55.55.00"'; my @list = $dsfe =~ /(\d)/g;
Re: split number into seperate numbers and store in an array or seperate variables
by BrowserUk (Patriarch) on Dec 17, 2008 at 23:03 UTC
Re: split number into separate numbers and store in an array or separate variables
by toolic (Bishop) on Dec 17, 2008 at 22:38 UTC
    When I run your code, it seems to work for me. Why do you think it doesn't work? What output do you get if you print @list
    use strict; use warnings; use Data::Dumper; my $dsfe_mask = q{String: "00.55.55.00"}; $dsfe_mask =~ s/\n|STRING: //g; $dsfe_mask =~ s/"+//g; $dsfe_mask =~ s/\D+//g; my @list = split(//,$dsfe_mask); print Dumper(\@list); __END__ $VAR1 = [ '0', '0', '5', '5', '5', '5', '0', '0' ];
Re: split number into seperate numbers and store in an array or seperate variables
by darienhuss (Initiate) on Dec 18, 2008 at 15:06 UTC
    thanks for all your help! i think the way I did it actually did work, just if you try and do just this print @list; for example, it doesn't print anything out. When you loop through the list and print out each separate variable it does work. My next problem is much more complicated and if I can't figure it out soon I'm going to create a new thread on it.