in reply to How to determine if an array passed as an argument to a subroutine is zero-length
#!/usr/bin/perl -wT use strict; my @arr = qw(a b c d e); # make a non-empty array my @arr2 = qw(); # make an empty array my $val = isempty(\@arr); # check if arr isempty my $val2 = isempty(\@arr2); # check if arr2 isempty print "\@arr ", $val ? 'is' : 'is not', " empty.\n"; print "\@arr2 ", $val2 ? 'is' : 'is not', " empty.\n"; sub isempty { my $aref = shift; # get array ref as param return !@$aref; # check array for emptiness } =output @arr is not empty. @arr2 is empty.
-Blake
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: How to determine if an array passed as an argument to a subroutine is zero-length
by Withnail (Novice) on Sep 07, 2001 at 21:06 UTC |