Dharshana Eswaran wrote:
> Hi All,

Hello,

> I have a string as shown below:
> 
> $string =
> "{[0]=0x53,[1]=0x65,[2]=0x63,[3]=0x75,[4]=0x72,[5]=0x69,[6]=0x74,[7]=0x79,[8]=0x43,[9]=0x6F,[10]=0x64,[11]=0x65,[12]=0x00}"
> 
> 
> This is stored as a string in a variable. I need to pull out only the
> numbers and store them in a array. Like:
> 
> @array = (53, 65, 63, 75, 72, 69, 74, 79, 43, 6F, 64, 65, 00);
> 
> I am unable to get a pattern to try pattern matching and spliting it.....
> 
> How do i do this?

$ perl -le'
my $string =
"{[0]=0x53,[1]=0x65,[2]=0x63,[3]=0x75,[4]=0x72,[5]=0x69,[6]=0x74,[7]=0x79,[8]=0x43,[9]=0x6F,[10]=0x64,[11]=0x65,[12]=0x00}";

my @array = $string =~ /[[:xdigit:]]{2}/g;

print "@array";
'
53 65 63 75 72 69 74 79 43 6F 10 64 11 65 12 00




John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to