perl - How to `local` multiple array elements at once? -


I rely on variables passing in some Pearl Sabratin Global.

So I'm trying to wrap Substrin after getting the argument, Local In Wars.

But looping on logic, each element is extracted in different code blocks.

Are I local in one of these elements in the code block? I want to pass the following test script:

  #! Use / usr / bin / perl strict; Use warnings; Test :: Use more; Our $ foo = 'foo'; Our $ bar = 'bar'; Our $ buz = 'buz'; My% arg = (foo = & gt; 'foo', bar = & gt; 'bar', buzz = & gt; 'buz',); Subtext test 1 = & gt; Sub [no rigid; Note that 'I need' local 'some variables'; Local $ {":: foo"} = 'FOO'; Local $ {":: bar"} = 'bar'; Local $ {":: buz"} = 'buzz'; $ Foo is 'FOO'; $ Bar, 'bar'; $ Buzz is 'buzz'; }; Subtext test 2 = & gt; Sub [no rigid; Note 'These variables are in% arg'; Note 'so I tried to eliminate it;' (Key% argument) {local $ {":: $ {$ _}"} = $ arg {$ _}; $ {$ _} Is $ arg {$ _}; }}; Subtext test3 = & gt; Sub [no rigid; Note 'How to get these local variables in the same code block?'; Note 'log block requirement code for logic'. '; (Key% argument) {local $ {":: $ {$ _}"} = $ arg {$ _}; } $ Foo is, 'FOO'; $ Bar, 'bar'; $ Buzz is 'buzz'; }; Subtext test = 4 = & gt; Sub [is $ fu, 'foo'; $ Bar, 'bar'; $ Buzz is 'buzz'; }; Done_testing ();  

Output:

  # subset: test1 # I need some local 'variable' ok 1 OK 2 OK3 1..3 OK 1 - Test 1 # Subtaste: test2 # These variables are in% arg. So I tried looping on it's fine 1 okay 2 fine 3 1..3 okay 2 - test2 #setestest: test3 # But how to get these local variables in the same code block? # Required Loops for Logic Code Block Not OK 1 # q.pl Failure on Line 52 # Found: 'FU' # Expected: 'Foo' Not OK 2 # q.pl Failed test on line # 53 # Found: 'Bar' # Expected: 'Bar' Not OK 3 # q.pl Failed test on line 54 # Found: 'buz' # Expected: 'Buzz' 1..3 # It seems that you have 3 trials Have failed in Not correct 3 - test3 # Failed test 'test3' # q.pl on line 55. # SubTest: Test 4 OK 1 OK 2 OK3 1..3 OK 4 - Test 4 1..4 # It seems that you have 4 1 of the tests have failed.  

I've temporarily created a hide hide space to store them

  subtest test3 = & gt; Sub (No strict 'refs'; Note 'How to get these local variables in the same code block?'; Note 'Loop requirement for code block.'; Hide my%; (Key% Arg) {($ Stash {$ _}, $ {"main :: $ _"}) = ($ {"main :: $ _"}, $ arg {$ _}) for $ Foo, 'FOO'; $ The bar is 'bay'; $ buzz is 'buzz'; (key% arg) {$ {"main :: $ _"} = $ hide instead {$ _};}};  

Thank you for all the respondents.

You can lose your local people D Ta is trying to run from the structure and list them as an example of your work.

Or, stop trying to use the local as described, all the local < / Code> stores the current value of the variable in a hidden pile for the duration of the current scope, you can save your value instead and restore yourself at the end of your test.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -