in reply to regexp problem - extract all but last part of SNMP OID

$oidfila =~ s/^[0-9\.]+(\.[0-9]+)$//;

This is already a good start, but you're matching - and thus substituting - too much. Leave off the first part and things will be ok:

$oidfila =~ s/\.[0-9]+$//;

Replies are listed 'Best First'.
Re^2: regexp problem - extract all but last part of SNMP OID
by kennethk (Abbot) on Nov 21, 2011 at 17:06 UTC
    Alternatively, if the initial condition is essential, you can use a capture on the lead in. This is inefficient, but necessary without variable-length look behind support.

    $oidfila  =~ s/(^[0-9\.]+)\.[0-9]+$/$1/;

      Which, according to perlre, can be written more efficiently with the "keep" construct:

      $oidfila =~ s/^[\d.]+\K\.\d+$//;