$q comes from the lines I didn’t include in order to keep things concise to the problem:
:local qid;
:local qplan 0;
:local qq;
:local qpm;
:foreach q in=[/queue simple find parent!=none] do={
The Queue names are things like V05_172.16.20.5, W03_172.16.20.14, H07_172.16.20.5, X10_172.16.20.15, B18_172.16.20.5, and S25_172.16.20.5.
So the goal with qpm is to get values like “5M”, “3M”, “7M”, “10M”, “18M”, and “25M”. We need to get rid of the leading 0.
And we want to use numerical values for qplan so we can compare to 0 which is why it needs to be numerical.
While your code works, it seems strange. Why is there “$”?
a string between quotes " ", the quotes start and stop the string
a variable $“qplan”, read the variable qplan and put it’s value on the string, quotes are used for not mix variable name qplan with M
a character M, simply put the letter M inside the string
Mikrotik scripting language is a strange beast, nothing like C, C++, C#, Java, PHP, JavaScript, Fortran, Cobol, Forth, 8086, M68k, 6800, TMS740, TMS720, 8051, or any of the other languages I know.
Every language has its peculiarities.
Java is very like C++. C++ is an extension of C so very similar.
PHP has a very C-like syntax and uses much of the C library. It also borrows extensively from Java and C++.
JavaScript is kind of similar to Java.
Fortran, Cobol, and Forth are like nothing else, especially Forth.
And Assembly is its own beast but all, except ARM, generally follow similar conventions.
But MikroTik script has a syntax all its own. It’s certainly not like C or PHP. In some ways its closer to Assembly.
To deal with the problem in PHP, it would be:
$qplan = intval(substr($qid,1,2));
$qpm = sprintf(“%dM”,$qplan);
or
$qplan = intval(substr($qid,1,2));
$qpm = strval($qplan).“M”;
In C, C++, C#, or Java, it would be:
int qplan;
char qpm[4];
qplan = int(substr(qid,1,2));
qpm = sprintf(“%dM”,qplan);
In JavaScript, it would be:
var qplan = Number(qid.substr(1,2));
var qpm = String(qplan) + “M”;
As you can see, none of them look anything like MikroTik Scripting.
Rumor has it that we will get a full-fledged MyPython in v7.11!
But to be honest, I’d be happy if it was just a real implementation of Nim, Lua, Tcl or something less crippled than the current RoS half-baked version of a scripting language (whatever it was based on).