Current time: 12-24-2024, 10:29 PM Hello There, Guest! (LoginRegister)


Poll: Do you want to beautify the perl code in the engine?
Yes
No
don't know
[Show Results]
 
Post Reply 
formatting style of the engine parts (perl)
Author Message
ispcomm Offline
Junior Member
*

Posts: 93
Joined: Apr 2008
Reputation: 3
Post: #30
RE: formatting style of the engine parts (perl)
Let's see. Variables and hashes like this is OK for me:
Code:
my $dmn_name     = @$dmn_data[1];
my $dmn_ip       = @$dmn_data[21];
my $conf_dir     = $main::cfg{'CONF_DIR'};
my $named_db_dir = $main::cfg{'BIND_DB_DIR'};
my $base_svr_ip  = $main::cfg{'BASE_SERVER_IP'};
my $sec_dns_ip   = $main::cfg{'SECONDARY_DNS'};

my %tag_hash = (
    '{DMN_NAME}'          => $dmn_name,
    '{DMN_IP}'            => $dmn_ip,
    '{BASE_SERVER_IP}'    => $base_svr_ip,
    '{SECONDARY_DNS_IP}'  => $sec_dns_ip,
    '{TIMESTAMP}'         => $time2
);
In perl this is acceptable (imho) as it crearly initializes the variables and is readable.
Code:
    my ($entry, $dns2_b, $dns2_e) = ('', '', '');
I'd keep the following structure intact as it shows the templates used and the return values. If I move everything on one line it gets unreadable:
Code:
    ($rs, $entry, $dns2_b, $dns2_e) = get_tpl(
        $tpl_dir,
        'db_e.tpl',
        'db_dns2_b.tpl',
        'db_dns2_e.tpl'
    );
    return $rs if ($rs != 0);
When this type of code becomes bigger, I think it can be written this way:
Code:
    my ($dta_b, $dta_e, $entry_b, $entry_e, $entry) = ('', '', '', '', '');
    (
        $rs,
        $dta_b,
        $dta_e,
        $entry_b,
        $entry_e,
        $entry
    ) = get_tpl(
        $tpl_dir,
        'cfg_dta_b.tpl',
        'cfg_dta_e.tpl',
        'cfg_entry_b.tpl',
        'cfg_entry_e.tpl',
        'cfg_entry.tpl'
    );
Or at maximum this way (which is less readable):
Code:
my ($dta_b, $dta_e, $entry_b, $entry_e, $entry) = ('', '', '', '', '');
(
    $rs,      $dta_b,   $dta_e,
    $entry_b, $entry_e, $entry
) = get_tpl(
    $tpl_dir,
    'cfg_dta_b.tpl',
    'cfg_dta_e.tpl',
    'cfg_entry_b.tpl',
    'cfg_entry_e.tpl',
    'cfg_entry.tpl'
);
I'm using tabs wherever possible. This will allow everybody to set the tab size to their liking (I prefer 3 for example).

Before I go and reformat these 3000+ lines another time, I'd prefer to get your approval first...
05-14-2008 01:40 AM
Find all posts by this user Quote this message in a reply
Post Reply 


Messages In This Thread
RE: formatting style of the engine parts (perl) - ispcomm - 05-14-2008 01:40 AM

Forum Jump:


User(s) browsing this thread: 7 Guest(s)