To expand on what mbethke said:
Think of each of your accounts as an entity that is self (pun intended) contained - It has information about that account stored in it and has methods that know what to do with that information.
Each of these entities could be an object, the template for which is defined by the class that you write like so:
package My::Twitter::Account;
use strict ;
use warnings ;
....
sub new {
my $class = shift;
my %parameter_hash;
my $count = @_;
%parameter_hash = @_;
croak( "MISSING FILE : \n " . $useage_howto ) unless( $
+parameter_hash{ FILE } ) ;
croak( "MISSING HEADINGS: \n " . $useage_howto ) unless( $
+parameter_hash{ HEADINGS } ) ;
croak( "MISSING NAME : \n " . $useage_howto ) unless( $
+parameter_hash{ NAME } ) ;
$parameter_hash{ DEBUG } = 0 unless( $parameter_hash{ DEBUG } );
my $self = {
FILE => $parameter_hash{ FILE } ,
HERADINGS => $parameter_hash{ HEADINGS } ,
NAME => $parameter_hash{ NAME } ,
SOME_USEFUL_INFO_MAYBE => $other_useful_info ,
DEBUG => $parameter_hash{ DEBUG } ,
}
bless( $self, $class );
dump( $self ) if( $self->{DEBUG} == 1 );
return $self;
}
...
Other Methods that deal with a SINGLE twitter account here.
Now that we have something to deal with a single account we can combine these either into a second package or decide to use them in a non-OO way. Lets do the First:
package My::Twitter::AllAccounts;
use strict ;
use warnings ;
... blah blah blah
sub new {
my $class = shift;
my %parameter_hash;
$parameter_hash{ DEBUG } = 0 unless( $parameter_hash{ DEBUG } );
my @twitter_accounts ;
my $self = {
TWITTER_ACCOUNTS => \@twitter_accounts ,
DEBUG => $parameter_hash{ DEBUG } ,
}
bless( $self, $class );
dump( $self ) if( $self->{DEBUG} == 1 );
return $self;
}
sub add_twitter_account {
my $self = shift ;
my $name = shift ;
my ( $file, $headings ) = _function_that_gets_files_and_headi
+ngs(); # This can also be inside the Twitter::Account class.
my $twitter_account = new My::Twitter::Account(
NAME => $name ,
FILE => $file ,
HEADINGS => $headings ,
);
push( @{ $self->{ TWITTER_ACCOUNTS } }, $twitter_account ) ;
return 1;
}
Now we have a way to store a single twitter account and a way to store the collection we can do things like:
my $twitter_data = new My::Twitter::AllAccounts() ;
my @accounts = qw(
Lady_Aleena
LadyAleena_ABC
LadyAleena_CBS
LadyAleena_FOX
LadyAleena_NBC
LadyAleena_SyFy
LadyAleena_TNT
LadyAleena_USA
LadyAleena_TV
LadyAleena_eros
LadyAleena_home
LadyAleena_test
);
foreach my $account ( @accounts ) {
$twitter_data->add_twitter_account( $account );
}
Of course the really fun part begins now:
# Am assuming you move your functions into the correct classes and wri
+te some ... But the below is just for illustration.
$twitter_data->reload_account_data( $account_name );
$twitter_data->get_sum_of_all_accounts();
$twitter_data->remove_twitter_account( $account );
$twitter_data->temporarily_ignore_accounts( [ account1, account2 ] );
$twitter_data->get_sum_of_all_accounts();
$twitter_data->stop_ignoring();
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.