How to process this command line plusarg?

I need to process the following plusarg from command line:

+my_arg_0=<some_value>
+my_arg_1=<another_value>
+my_arg_2=<yet_another_value>

and so on.

I don’t want to create separate variables such as my_arg_0, my_arg_1 etc. There are too many of them. I have an array of my_arg variables, where I want to keep the value obtained from the command line. So I need to process “my_arg_” and the following number separately.

I know it’s quite easy to do in PERL, but how can I do it in systemverilog/uvm?

In reply to 1978bubun:

You can do

foreach (my_arg[i]) void'($value$plusargs($sformatf("my_arg_%0d=%%d",i), my_arg[i]));

In reply to dave_59:

Hi Dave,

Thanks, but could you check the syntax one more time? I am getting the following error:

Error-[STASKE_VPAMHFS] Invalid argument to $value$plusargs

An invalid plusarg_format string ‘num_sets_0=’ is passed as first argument
to $value$plusargs.
Please ensure that the first argument to $value$plusargs is a valid
plusarg_format specifier string.

This is my code:

    foreach (ovrd_num_sets[i]) void'($value$plusargs(($sformatf("num_sets_%0d=",i)), ovrd_num_sets[i]));

In reply to 1978bubun:

Sorry, forgot the %%d. See corrected example.

In reply to dave_59:

In reply to 1978bubun:
Sorry, forgot the %%d. See corrected example.

Thanks a lot, Dave! This worked.

In reply to dave_59:

Hi Dave,

I wonder what is special about %%d? I tried to modify the code to


foreach (my_arg[i]) void'($value$plusargs($sformatf("my_arg_%0d=%0d",i), my_arg[i]));

and it failed during compilation.

So I’m wondering why %%d works but %0d fails?

Thanks

In reply to peterjin:

%% is is an escape so %%d gets passed through $sformat as %d to $value$plusargs.