Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Seeking guidance for more idiomatic way of (re)writing this script.

by Athanasius (Canon)
on Jan 15, 2013 at 03:31 UTC ( #1013305=note: print w/ replies, xml ) Need Help??

in reply to Seeking guidance for more idiomatic way of (re)writing this script.

Two suggestions:

  1. Wherever possible, avoid scattering hardcoded constants throughout the code. Instead, aim to make the script easily configurable. As a first step, move any data which could change into a hash:

    my %config ( smtp_destination => '', nas_array_ip_list => 'C:/path/to/nas_array_ip_list.txt', smtp_msg_from => '', smtp_msg_to => '', mail_file => 'C:/path/to/dmcheck.txt', username => 'username', password => 'password', reason => '/nas/sbin/getreason', nasmailmsg_from => '', nasmailmsg_to => '', dm_check => 'dmcheck.txt', );

    and access the hash data as needed:

    MIME::Lite->send('smtp', $config{smtp_destination}); if (! open my $fh, '<', $config{nas_array_ip_list}) ...

    As the next step, you may find it useful to populate the hash by reading in the data from a separate configuration file.

  2. Avoid system calls where Perl has equivalent built-in functions. So, replace

    system 'del dmcheck.txt';


    unlink $config{dm_check} or warn "Could not unlink file '$config{dm_ch +eck}': $!";

    See unlink.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Comment on Re: Seeking guidance for more idiomatic way of (re)writing this script.
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1013305]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2015-10-09 20:53 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (251 votes), past polls