können Sie substr
verwenden:
substr ($nsap, -2) = "F0";
oder
substr ($nsap, -2, 2, "F0");
Oder Sie können eine einfache regex verwenden:
$nsap =~ s/..$/F0/;
Das von substr
‚s Manpage ist:
substr EXPR,OFFSET,LENGTH,REPLACEMENT
substr EXPR,OFFSET,LENGTH
substr EXPR,OFFSET
Extracts a substring out of EXPR and returns it.
First character is at offset 0, or whatever you've
set $[ to (but don't do that). If OFFSET is nega-
tive (or more precisely, less than $[), starts
that far from the end of the string. If LENGTH is
omitted, returns everything to the end of the
string. If LENGTH is negative, leaves that many
characters off the end of the string.
Nun ist der interessante Teil ist, dass das Ergebnis der substr
kann als L-Wert verwendet werden, und zugewiesen werden:
You can use the substr() function as an lvalue, in
which case EXPR must itself be an lvalue. If you
assign something shorter than LENGTH, the string
will shrink, and if you assign something longer
than LENGTH, the string will grow to accommodate
it. To keep the string the same length you may
need to pad or chop your value using "sprintf".
oder Sie können das Ersatz Feld verwenden:
An alternative to using substr() as an lvalue is
to specify the replacement string as the 4th argu-
ment. This allows you to replace parts of the
EXPR and return what was there before in one oper-
ation, just as you can with splice().