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

Leave a Reply

Your email address will not be published.