This substitution
s{(?<=\s)(\S+)}{
my $entry = $1;
my @fields = split '\|', $entry;
$lookup{$fields[1]} // $entry;
}eg;
uses the /e
modifier, which indicates that the replacement string is not to be used directly, but executed as Perl code to generate the string to replace the match.
The match finds the next sequence of non-space characters that follow a space character, so in this case
$1
is initially set toL#'|NA|det
$1
is copied to$entry
, and$entry
is split on the pipe characters|
into@fields
The
%lookup
hash is indexed with$fields[1]
- the second entry in@fields
. Here that is the stringNA
The code block returns the value of that hash element, or the whole of
$entry
if there was no hash element with that key. Note that, because$entry
is the whole of the matched string, there is no change unless a corresponding element is found in%lookup
because the string is replaced with itself
I hope this helps