Hello, the pearl syntax is not familiar, but you need to implement a random value between one and two after the function is executed. There is a function that depends on the parameter, which is set to 2.

Generate(17, "test",3,1 , 2); 

in general, it doesn't matter what the first arguments mean, only the last one is important. In the function itself, its value is set as follows:

 my %values = ('CAT' => $dbCategoryUrl,'CATNAME' =>$dbCategoryName , 'TEST' =>$test ); 

and the value takes only 2 after execution. Tell me how to implement the function so that a random value of 1 or 2 is issued after the execution. thank

    1 answer 1

    To get a random number 1 or 2, use this design

      int(rand(2)+1) 

    Is it possible to make them alter?

    could be so

     #!/usr/bin/perl use 5.018; use strict; use warnings; { my $counter = 1; sub getNext { $counter = 3 - $counter; return $counter; } } for (1..100) { print getNext(), "\n"; } 
    • That is, my function will look like this: my% values ​​= ('CAT' => $ dbCategoryUrl, 'CATNAME' => $ dbCategoryName, 'TEST' => int (rand (2) +1)) ;, or in arguments first change to Generate (17, "test", 3.1, int (rand (2) +1)); - Apemother
    • I would leave the generation inside the function (that is, the first option). Judging by her name, it is expected. And transmitting the parameter of the black box from the outside world ... is not too confusing. - KoVadim
    • Thank. Is it possible to make them alter? - Apemother