On 04/05/2011 13:30, loudking wrote:
Hi there,
Hereby I have a string parsing problem to ask. The sample strings look
like this:
00000000: CC02 0000 0565 0000 8E93 D501 0100 6273 .....e........b
00000000: 6800 0000 0500 0000 9093 D501 0100 1400 h...............
What I am interested is the the 21st and 22nd byte value. In the above
examples, they are both 05.
Could anybody tell me how to retrieve that value out of the strings
using regular expression?
Thanks in advance!
First of all, it would be far better to open whatever is being dumped
here and evaluate the fifth byte directly, rather than dumping it and
parsing the dump. However I realise that there may be reasons why this
is not possible.
The program below uses unpack to extract two characters after the 20th
on each line that contains a colon.
HTH,
Rob
use strict;
use warnings;
while (<DATA>) {
next unless /:/;
my $byte = unpack '@20 A2';
print $byte, "\n";
}
__DATA__
00000000: CC02 0000 0565 0000 8E93 D501 0100 6273 .....e........b
00000000: 6800 0000 0500 0000 9093 D501 0100 1400 h...............
**OUTPUT**
05
05
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/