Bootstrap FreeKB - Perl (Scripting) - Print last value in an array in Perl
Perl (Scripting) - Print last value in an array in Perl

Updated:   |  Perl (Scripting) articles

Let's say you have an array of fruit.

my @fruit = qw(apple banana orange grapes);

 

The following will print the last value in the array (grapes in this example).

print $fruit[$#fruit];

 

Likewise, you could store the last value in a new variable.

my $last_value = $fruit[$#fruit];

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


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