Community discussions

MikroTik App
 
crashpunk
just joined
Topic Author
Posts: 10
Joined: Sat Apr 05, 2008 9:36 pm

Variable Variable... But.. In Mikrotik..??

Sat Apr 05, 2008 9:57 pm

Hello.. I Have A Problem.. I Can't Set a Variable Variable in Mikrotik RouterOS..
Variable Variable Is translated as.. The Result of The First Variable is The Name of The Second Variable.. eg with PHP:

$a = "Hello";

$$a = "What's Up"; ( This Is The Same To Put [ $Hello = "What's Up" ]...

But I have not Name of The Second Variable.... Need to Use Variable Variable...

And I tried with:

:local a "Hello";
:local $a "What's Up"; ( But Not Work )

or:
:put $aa; ( But Not Work )

Help Me... Thanks.. ^^ (My English Is Bad.. Sorry)..
 
User avatar
Letni
Member
Member
Posts: 376
Joined: Tue Dec 05, 2006 5:16 am
Location: South Carolina

Re: Variable Variable... But.. In Mikrotik..??

Sun Apr 06, 2008 7:08 am

When you initialize the variable you can set it in one shot.
ex:
:local a "Hello"

Then if later in the script you want to change the value of a you use set.
:set a "What's Up"

Demo (Tested on V3.6)
:local a "Hello"
:log info "a is: $a"
:set a "What's Up"
:log info "a is: $a"
-Louis
 
sten
Forum Veteran
Forum Veteran
Posts: 919
Joined: Tue Jun 01, 2004 12:10 pm

Re: Variable Variable... But.. In Mikrotik..??

Mon May 12, 2008 3:53 pm

Hello.. I Have A Problem.. I Can't Set a Variable Variable in Mikrotik RouterOS..
Variable Variable Is translated as.. The Result of The First Variable is The Name of The Second Variable.. eg with PHP:

$a = "Hello";

$$a = "What's Up"; ( This Is The Same To Put [ $Hello = "What's Up" ]...

But I have not Name of The Second Variable.... Need to Use Variable Variable...

And I tried with:

:local a "Hello";
:local $a "What's Up"; ( But Not Work )

or:
:put $aa; ( But Not Work )

Help Me... Thanks.. ^^ (My English Is Bad.. Sorry)..
I've been missing such a feature since 2.8.
There is a crude way of doing it but it does wear on your flash.

:global a "something"
:global b "a"
/ system script run [ / system script add name=assigna source=( ":set b " . $a ) ]
:delay 10ms
:put $b

(Written from memory, YMMV)

Who is online

Users browsing this forum: Jonty and 24 guests