FreeKB - Perl (Scripting) Remove all elements from array (undef)
Perl (Scripting) - Remove all elements from array (undef)

Let's say the @fruit array contains 4 elements.

my @fruit = qw(orange apple peach pear);

 

In this example, the $count variable will contain the number of elements in the @fruit array.

my $count = "";
$count = @fruit;

 

You can print the $count variable;

print $count;

 

Which will return 4, meaning there are 4 elements in the @fruit array.

4

 

The undef operator can be used to remove all of the values from the array. Once undefined, the array will no longer contain any values.

undef @fruit;

 

The $count variable can be used again to contain the number of elements in the @fruit array.

$count = @fruit;

 

You can print the $count variable;

print $count;

 

Which should return 0, meaning there are now 0 elements in the @fruit array.

0


Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 6d36f in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |