in reply to Re: Recover Excel data from cells with Foreach loop
in thread Recover Excel data from cells with Foreach loop

Thank you Poj ! But why is it ignoring the spreadsheet?

I've checked and it's working fine, thx ! Otherwise, is there a way to do it with a loop, "foreach" or "for"?!

Thanks again

  • Comment on Re^2: Recover Excel data from cells with Foreach loop

Replies are listed 'Best First'.
Re^3: Recover Excel data from cells with Foreach loop
by poj (Abbot) on Nov 10, 2018 at 21:46 UTC

    see foreach loops in perlsyn. Your foreach loop iterates over the list values of 0 to 9 and sets the scalar variable $data to be each element of the list in turn. Because the variable is preceded with the keyword my, then it is lexically scoped, and is therefore visible only within the loop.

    Try

    #!/usr/bin/perl use strict; use Spreadsheet::Read; my $excel = ReadData("TEST.csv"); my $maxrow = $excel->[1]{maxrow}; for my $row (1 .. $maxrow){ my $url = $excel->[1]{'A'.$row}; # do something with url process($url); } sub process { my ($url) = @_; print "Processing $url\n"; }
    poj

      Hmmm ; I understand better now. Thx. I need to work more with the foreach loop

      Further to that i have a latest remark Poj. I would like to make a screenshot once an url is opened; As i am in a loop, i would like to store for each url a screnshot file. I did quickly as follows. I got no error but i got no screenshot :)

      I used your code

      sub process { my ($url) = @_; print "Processing $url\n"; # selenium code etc $driver->get($url); $driver->maximize_window(); $driver->pause(2000); #my $filename = "screenshot.png"; #$driver->capture_screenshot($filename); my $path = "C:/Users/user1/Documents/TESTPERL"; $driver->capture_screenshot("$path/Website-$url.png"); $driver->pause(2000); }

      Many thanks Poj

        Hi, poj has the night off ;-)

        You don't check to see whether your call to capture_screenshot succeeded. It returns true if so, and nothing if it fails.

        $driver->capture_screenshot("$path/Website-$url.png") or warn "Didn't +get it!";

        Since the call is not raising an exception, it's hard to guess what the problem might be: if the file could not be opened or written to, you would have encountered a fatal error, for example. If you turn on debugging you might see some issue with the driver itself, or maybe diagnostics from the Perl module ...

        $driver->debug_on();

        Like I say I cannot really think of a cause of your issue: I have used the command successfully myself many times, FWIW.

        Hope this helps!


        The way forward always starts with a minimal test.