How can I re-establish a network connection in a Perl script?
I have a Perl code which goes to particular website and ex开发者_运维百科tracts the required data from it. I face a problem if I lose my connection: the script stops functioning. How could I make the Perl script resume the connection and start the process from where the interruption took place? Can I use the Perl to resume the connection if so could any one guide me with the steps please.
It is not possible to do this. Once a transport-level network (e.g. TCP/IP) connection is broken you cannot get it back again. And the HTTP protocol does not provide a higher level way of doing this.
You have to open a new HTTP connection to the server and restart your extraction. Whether you have to restart from the beginning, or can resume close to where you were when the connection broke depends on what it is you are fetching, how the website presents it, and the client-side tool you are using to do the fetching.
On the off chance that you mean you've lost your dialup connection and you are on windows, the answer is to call the rasdial command using system().
What do you mean when you say "lose my connection" and "goes to a website and extracts data"? Is your perl code managing the Socket Connection and the data scraping itself or are you using a higher level Perl library like LWP or WWW::Mechanize to "extract data"
If the latter then you might like to read this question and the answers
精彩评论