FreeKB - Print last value in an array in Perl
Print last value in an array in Perl

Home > Search


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];

 



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 9a212 in the box below so that we can be sure you are a human.




Comments