2

I am working on kernel module and the module outputs a hex code which is being read by a perl script using regex.

I am not able to make sense out of it:

while (<>) {
    s/^([a-fA-F0-9]+)(\.)([a-fA-F0-9]+)(\s+.*)/sprintf("%s%s%s%s",  &$converter(hex($1)), $2, hex($3), $4)/oe;
} continue {
    print;
}

We are trying to read hex code to time in nano second.

Rizwan M.Tuman
  • 9,424
  • 2
  • 24
  • 40
MikasaAckerman
  • 522
  • 3
  • 16

1 Answers1

1
s/^([a-fA-F0-9]+)(\.)([a-fA-F0-9]+)(\s+.*)/sprintf("%s%s%s%s",  &$converter(hex($1)), $2, hex($3), $4)/oe;

There are 4 capturing groups, each is covered by brackets ():

$1 -> ([a-fA-F0-9]+)

$2 -> (\.)

$3 -> ([a-fA-F0-9]+)

$4 -> (\s+.*)

Details here

yonyon100
  • 920
  • 8
  • 23
Rizwan M.Tuman
  • 9,424
  • 2
  • 24
  • 40