Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: match two elements from an array in a row

by shoness (Friar)
on Aug 17, 2007 at 08:53 UTC ( #633247=note: print w/replies, xml ) Need Help??


in reply to match two elements from an array in a row

Just for fun, I wanted to try this with the regexp engine...
#!/usr/bin/perl use strict; use warnings; my @data = qw ( 01 b2 01 00 b6 81 81 01 b4 0a 01 01 01 01 00 01 00 00 01 00 c7 82 82 01 b2 01 00 b8 ); $_ = join(' ', @data); while ( /(8[[:xdigit:]])\s+\1/g ) { print "Duplicate $1 found at character " . pos() . "\n"; }
Produces...
bash$ superdoc.pl Duplicate 81 found at character 20 Duplicate 82 found at character 68
Using...
# while ( /([[:xdigit:]]{2})\s+\1/g ) {
instead, will match any repeated hex digit...
bash$ superdoc.pl Duplicate 81 found at position 20 Duplicate 01 found at position 35 Duplicate 01 found at position 41 Duplicate 00 found at position 53 Duplicate 82 found at position 68
Cheers!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://633247]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2020-10-27 18:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (257 votes). Check out past polls.

    Notices?