0

I'm new to perl with regex.

I'm trying to have a string of oid 1.3.6.1.2.1.4.22.1.2.*.192.168.1.1, but I'm not sure how to do it. I tried the below, but it is getting error which is saying not able to recognize the oid.

my $matchanyoid = "/(\d+)$/";
my $dot1dTpFdbAddress = '1.3.6.1.2.1.4.22.1.2.',$matchanyoid,'\.',$srcip;

1 Answer 1

1

Comma is not a concatenation operator, dot is:

my $dot1dTpFdbAddress = '1.3.6.1.2.1.4.22.1.2.' . $matchanyoid . '\.' . $srcip;

If you are trying to build a regular expression, note that the first several dots are not backslashed, so they can match anything. To avoid lots of backslashes, you can use the \Q ... \E construct:

my $matchanyoid = '(\d+)';
my $srcip = 12;
my $regex = qr/\Q1.3.6.1.2.1.4.22.1.2.\E$matchanyoid\.$srcip/;
print '1.3.6.1.2.1.4.22.1.2.123.12' =~ $regex;
Sign up to request clarification or add additional context in comments.

3 Comments

I got the error: ERROR: The base OBJECT IDENTIFIER "(?^:1\.3\.6\.1\.2\.1\.4\.22\.1\.2\.\/(d\+)\\.192\.1168\.1\.32)" is expected in dotted decimal notation.
@kyusan93: Then you are probably not telling us all the important details. I updated the answer, it works for me.
I'm trying to use Net::SNMP to get the mac address via oid, but I only know the ip address and the 1.3.6.1.2.1.4.22.1.2, but between the 1.3.6.1.2.1.4.22.1.2 and the IP, there is some other * numbers and I do not how to use the perl regex to do the *.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.