sandcrawler has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; use LWP; use HTTP::Request::Common; use WWW::Mechanize; use XML::Simple; use Data::Dumper; use Encode; use Parallel::ForkManager; use IPC::Shareable; my glue = 'data'; my %options = ( create => 'yes', exclusive => 0, mode => 0600, destroy => 'yes', ); my @weather; my $shm = tie @weather, 'IPC::Shareable', $glue, { %options } or die " +Could not create shm\n"; # Fetch the snapshot $mech->get("http://mainurl.com/weather.jsp"); $mech->form_name('snapshotform'); $mech->field( 'userid', 'foo' ); my $snapshot = $mech->submit(); # split the snapshot into an array my @tmp = split( "\n", $snapshot->{_content} ); # put the CSV data into a list of lists for (@tmp) { push @weather, [ split(",", encode ( "UTF-8", "$_") )]; } ## Now that I have basic weather data I need to look at that list and +retrieve the extended data. ## my ($temp, $humid); my $pf = new Parallel::ForkManager(3); for (my $i = 0; $i < scalar(@records); $i++) { my $pid = $pf->start and next; $mech->get( "http://someurl.com/weather.jsp?zipcode=" . $weather[$i][1 +]); my $html = $mech->content( format => "text" ); ## The data comes back in tables upon embedded tables and I've found i +t easiest to just regex the values I need. ## unless ( ($temp) = ( $html =~ /some (regex)/ ) ) { $temp = "NULL" } unless ( ($humid) = ( $html =~ /some (regex)/ ) ) { $humid = "NULL" } $shm->shlock; push( @{ $weather[$i] }, "$temp", "$humid" ); $shm->shunlock; $pf->finish; } $pf->wait_all_children; ## More code that pushes the data to a database. ###EOF###
and so on...$var1 = [ SomeTown, 12345, 13:00, 65, 80 ] $var2 = [ SomeOtherTown, 23456, 13:00, 72, 45 ]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parallel::ForkManager and IPC::Shareable
by derby (Abbot) on Apr 30, 2009 at 23:21 UTC |