Perl Last Element of Split

There is an easier way to get last element on a split operation, save split result to an array and use $array[-1] and this will access last element of the arrays.

Example

$strings=”foo,bar,test”;
my @fields = split(/,/, $strings);
print $fields[-1] ;  # the last str in $strings


Comments

17 responses to “Perl Last Element of Split”

Leave a Reply