#!/usr/bin/env perl use 5.016; use warnings; use Carp::Always; BEGIN { *CORE::GLOBAL::exit = sub { die } } END { say "END block"; } my $crawler = Crawler->new; $crawler->run; die; package Crawler { use parent 'LWP::UserAgent'; # use a bunch of other modules for the processing. sub new { my $self = $class->SUPER::new(%args); $self->{ids} = (1..100); # These normally are pulled from a DB. return $self; } sub run { my $self = shift; my @idx = shuffle 0 .. -1 + @{ $self->{ids} }; my $cur = 0; for my $i (@idx) { my $id = $self->{ids}[$i]; printf "%d/%d: %s (%d)\n", ++$cur, 0+@idx, $id, $i; # Fetch and process stuff related to this id. } } sub DESTROY { say "Crawler destroyed" } }