in reply to how can this be improved?
I'm not sure about that whole $recipient thing. Are you expecting an argument?unless ($^O =~ /aix/) { die ... } # might be better as die ... unless $^O =~ /aix/;
I'm going to idiomatize your while-loop.my $sequence_number = shift || die ...; # technically, you want 'or' instead of '||' here open (ERROR, "/usr/bin/errpt -g -l $sequence_number |"); # you don't check to see if it opened properly... # nor do you ensure the safety of the variable # if I enter '; rm -rf' here, you're in trouble my ($sequence_number) = shift =~ /(\d+)/ or die ...; open ERROR, "/usr/bin/errpt -g -l $sequence_number |" or die "can't run errpt -g -l $sequence_number: $!";
Your hex-to-ascii stuff can be replaced by using "H*" instead of "C". The only other thing I'd change is your @mail array and ALL those sprintf()s.while (<ERROR>) { $message{host} = (split)[1], next if /^el_nodeid/; $message{drive} = (split)[1], next if /^el_resource/; $message{detail} = (split)[1], next if /^el_detail_data/; }
It's condensed somewhat, and the data structure still represents the pairing between text and variable. And, if you need to change the format, you change it once.printf SENDMAIL "%-16s: %-20s\n" => @$_ for ["Sequence Number" => $sequence_number], [ Host => $message{host} ], [ Drive => $message{drive} ], [ Model => $message{model} ], [ Microcode => $message{mml} ], [ "Message Type" => $message{type} ], [ "Message Code" => $message{code} ], [ Severity => $message{severity} ], $message{type} eq "SIM" ? ( [ "First FSC" => $message{first_fsc} ], [ "Last FSC" => $message{last_fsc} ], ) : ( [ VOLSER => $message{volser} ], );
_____________________________________________________
Jeff[japhy]Pinyan:
Perl,
regex,
and perl
hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: how can this be improved?
by blueflashlight (Pilgrim) on Aug 21, 2001 at 22:08 UTC |