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

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

Replies are listed 'Best First'.
Re^4: Recover Excel data from cells with Foreach loop
by Perlchaoui (Sexton) on Nov 10, 2018 at 22:33 UTC

    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.

        Hello @lnickt !

        Thank you for your feedback.

        Yes i guess @Poj has got a life :)

        Indeed, yes, i have no trace of the issue..I tried as you recommanded with that

        $driver->debug_on();

        But i just got log from server and the information's are not clear on the potential issue.I will try again :)

        PS: A question: How is it possible to add a link to a monk for a reply. Like this : @Poj .For instance. Thanks