I have an array and hash. I just want to check whether they both are empty or not.
I found below two methods to check this. Any suggestion which would be more suffice.
#!/usr/bin/perl
use strict; use warnings;
use Data::Dumper;
my @a = qw/a b c/;
print Dumper(\@a);
my %b = (1 => "Hi");
print Dumper(\%b);
@a = ();
%b = ();
#Method 1
if(!@a && !%b){
print "Empty\n";
} else {
print "Not empty\n";
}
#Method 2
if(!scalar @a && !scalar keys %b){
print "Empty\n";
} else {
print "Not empty\n";
}
The case here is, either both would be Empty or both would have some values.