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.

Mustofa Rizwan
  • 10,215
  • 2
  • 28
  • 43
MikasaAckerman
  • 531
  • 5
  • 17

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

yoniyes
  • 1,000
  • 11
  • 23
Mustofa Rizwan
  • 10,215
  • 2
  • 28
  • 43