in reply to Recover a variable from a loop

The errors you are getting are within the foreach loop, so they don't appear to have something to do with the loop itself or with scoping issues related to the loop.

I do not know Selenium, but my best guess is that the Selenium::Screenshot->new constructor invocation did not return a defined object. Check whether $white is defined right after that constructor invocation. It seems likely you might have a problem there.

Replies are listed 'Best First'.
Re^2: Recover a variable from a loop
by Chaoui05 (Scribe) on May 26, 2016 at 09:28 UTC
    Hello Laurent ! Concerning my constructor , it seems to work. When iam doing comparison within my loop , all is ok. Why i want to do comparison outside? Because i have to get all my browser' screenshots to be able to compare them. And my foreach return for each browser its screenshots. And if i want to compare 2 screenshots for 2 different browser, i think i have to do comparison outside loop.
    Lost in translation
      Then I have probably misunderstood your problem.

      But you report this error:

      Global symbol "%white" requires explicit package name at MyTest.pm lin +e 33.
      And, in the code that you have shown, line 33 is within the loop.

      If the code you show is not exactly the same as the one you run, it is difficult for us to figure out where exactly the error is occurring.

      Looking at it again, the error seems to be in:

      unless ($white{browser_name => $browser[0]} ...
      in which you use 'white' as a hash %white, not a scalar $white. Besides, $white has fallen out of scope anyway, so you would not be to access $white either, unless you had declared it before the start of the loop.