in reply to Re^4: weird issue with HTML::TokeParser and Fork
in thread [Click the star to watch this topic] weird issue with HTML::TokeParser and Fork

What's with the fork at the end of the while($ref = $result->fetchrow_hashref) loop?

$data and $result are being destroyed in each of your children. That can have unfortunate side effects. You should be using _exit (in POSIX) instead of exit.

General rule: require and use are for modules that have a package statement. do is for those without. This applies here.

As for your actual question, turn on your warnings and pay attention to them. You should be getting a few "Subroutine insertrecord redefined" errors. Suggested fix:

#!/usr/bin/perl ... use Scraping::Amazon; ... Scraping::Amazon::get($ref->{OEM_PartNum}, $ref->{Description}); ...

scraping/amazon.pm: (File "amazon.pm" — note the extension change — in subdirectory "scraping")

package Scraping::Amazon; ... sub get { ... } sub insertrecords { ... } 1;

You don't have to use a subdirectory. Just remove "Scraping::" from everywhere if you put the modules in the same dir as the main script.

Replies are listed 'Best First'.
Re^6: weird issue with HTML::TokeParser and Fork
by arikamir (Initiate) on May 06, 2008 at 14:59 UTC
    the fork at the end of the loop is a typo, I took it off. If I understand your recommendation correctly you would package the sub scripts. I don't get how that will affect the destruction of $data and $results, and if $data and $result are being destructed in the child processes is a problem, does that mean that I can set the $sqlstatement from the child processes and execute it in the parent process (which would save on a connection to the DB)? Thanks