Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: match two elements from an array in a row

by graff (Chancellor)
on Aug 17, 2007 at 03:02 UTC ( [id://633210]=note: print w/replies, xml ) Need Help??


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

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 ); for ( 1 .. $#data ) { if ( $data[$_] =~ /(8[12])/ and $data[$_] eq $data[$_-1] ) { print "Match $1 ending at index $_\n"; } }
(update: rearranged my conditions as perl Kanji's premature optimization. :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-25 16:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found