c has asked for the wisdom of the Perl Monks concerning the following question:
&log_action(\%args);
In my mains code, I test for an error and then stuff the value into $args{err} (This is being done through a Net::SNMP function)
$args{err} = $s->error();
Now, within the log_action subroutine, I pull in my hash reference
sub log_action { my $args = shift;
And I test to see if there is was an error message
if ($args->{err}) { # do something...
Is this a suitable method? I read through defined and exists and it seems as though
if (defined $args->{err}) {
may be more appropriate. How does perl judge if (args->{err}) when neither is used?
And as a follow up question regarding whether defined or exists is the better to use... If there is no error returned via the Net::SNMP call, according to its documentation, it "returns an empty string". Please correct me if I am wrong, but this means that there will be a hash key present called $args{err} but there will be no value associated with it?
Thanks -c